【发布时间】:2015-03-10 14:24:27
【问题描述】:
目前,我的 uipicker 有 3 个选项,Cameron、Shaffer 和 Hydril。当我选择 Cameron 时,我希望我的 uitableview 加载 camerondata1。如果我选择 Shaffer,我希望它加载 camerondata2。
如何设置我的 UItableview 以根据我的选择器视图上所做的选择重新调整?我是 Swift 编程新手。
class Picker2: UIViewController, UIPickerViewDelegate, UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate
{
var activeTextField:UITextField?
let textCellIdentifier = "TextCell"
let camerondata1 = ["Working Pressure (psi): 5,000", "Fluid to Close (gal): 1.69",]
let camerondata2 = ["Working Pressure (psi): 10,000", "Fluid to Close (gal): 2.69",]
@IBOutlet var pickerView1: UIPickerView!
@IBOutlet var textField1: UITextField!
var brand = ["Cameron","Shaffer", "Hydril"]
override func viewDidLoad() {
super.viewDidLoad()
pickerView1 = UIPickerView()
pickerView1.tag = 0
pickerView1.delegate = self
self.view.addSubview(textField1)
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
if pickerView.tag == 0 {
return brand.count
}
return 1
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
if pickerView.tag == 0 {
return brand[row]
}
return ""
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerView.tag == 0 {
textField1.text = brand[row]
}
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return camerondata1.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as UITableViewCell
let row = indexPath.row
cell.textLabel?.text = camerondata2[row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
let row = indexPath.row
println(camerondata1[row])
}
}
【问题讨论】:
标签: xcode uitableview swift uipickerview