我有一个viewController
有一堆输入的。其中一些是普通文本,但有些需要选择器的输入。我决定将每个的实现PickerDelegate
移到PickerDataSource
一个单独的文件中,以使事情变得更简洁。数据正在出现,但在选择 Picker 时,我不知道如何让事件在我的 viewController 中触发。目前它只在 PickerDelete 类中触发。
一些基本的布局信息是
class MyClass: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
let jobTypePickerValues = ["value1", "value2"]
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
// returns the # of rows in each component..
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return jobTypePickerValues.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return jobTypePickerValues[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
//println("I want this in the view controller that set up the picker")
}
在显示选择器的视图控制器中,我有以下内容
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
myClassSource = MyClass()
pickerView = UIPickerView()
pickerView.dataSource = myClassSource
pickerView.delegate = myClassSource
// set the input view of the job type to be a picker view
textInput.inputView = pickerView
textInput.text = jobTypePickerValues[0]
}