我在一个 View Controller 中创建了多个选取器,因此我必须使用单独的 Cocoa touch 类来处理每个选取器的数据源和委托(delegate)方法。我有这段代码:
myPicker.delegate = CustomPickerViewController
myPicker.dataSource = CustomPickerViewController
在这种情况下,CustomPickerViewController
是一个单独文件中的 cocoa touch 类,它实现了所需的 UIPickerViewDelegate
和 UIPickerViewDataSource
方法。那么,我应该为上述属性分配什么,以便使用 CustomPickerViewController 类处理填充选择器 View ?
最佳答案
每个选择器都应该获得自己的 CustomPickerViewController
实例。
myPicker.delegate = CustomPickerViewController()
myPicker.dataSource = myPicker.delegate
anotherPicker.delegate = CustomPickerViewController()
anotherPicker.dataSource = anotherPicker.delegate
关于ios - 将选择器的委托(delegate)和数据源外包给 swift 中的另一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32960989/