将选择器的委托和数据源外包给 swift 中的另一个 class
Outsourcing the delegate and datasource of a picker to another class in swift
我在一个视图控制器中创建了多个选取器,因此我必须使用单独的 cocoa 触摸 class 来处理它们每个的数据源和委托方法。我有这个代码:
myPicker.delegate = CustomPickerViewController
myPicker.dataSource = CustomPickerViewController
在这种情况下,CustomPickerViewController
是一个单独文件中的 cocoa touch class,该文件实现了所需的 UIPickerViewDelegate
和 UIPickerViewDataSource
方法。那么,我应该为上述属性分配什么,以便使用 CustomPickerViewController class?
处理填充选择器视图
每个选择器都应该有自己的 CustomPickerViewController
实例。
myPicker.delegate = CustomPickerViewController()
myPicker.dataSource = myPicker.delegate
anotherPicker.delegate = CustomPickerViewController()
anotherPicker.dataSource = anotherPicker.delegate
我在一个视图控制器中创建了多个选取器,因此我必须使用单独的 cocoa 触摸 class 来处理它们每个的数据源和委托方法。我有这个代码:
myPicker.delegate = CustomPickerViewController
myPicker.dataSource = CustomPickerViewController
在这种情况下,CustomPickerViewController
是一个单独文件中的 cocoa touch class,该文件实现了所需的 UIPickerViewDelegate
和 UIPickerViewDataSource
方法。那么,我应该为上述属性分配什么,以便使用 CustomPickerViewController class?
每个选择器都应该有自己的 CustomPickerViewController
实例。
myPicker.delegate = CustomPickerViewController()
myPicker.dataSource = myPicker.delegate
anotherPicker.delegate = CustomPickerViewController()
anotherPicker.dataSource = anotherPicker.delegate