多个 UIPickerView 和数据源
我有两个 UIPickerViews 需要转到不同的数据源。我能找到的最接近的答案是: 多个 UIPickerViews
但我不知道如何执行以下操作:
您可以创建两个类 - 一个数据源对于每个选择器视图,并在 viewDidLoad 方法中手动将它们分配给选择器视图实例
似乎很简单,但代码确实使用了示例。
I have two UIPickerViews that need to go to different datasouces. The closest answer I could find was this:
Multiple UIPickerViews
But I can't figure out how to do the follwoing:
you can create two classes - one data source for each picker view, and manually assign them to the picker view instances in the viewDidLoad method
Seems easy, but code really use an example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为数据源创建两个类。它们显然应该派生自
NSObject
并实现UIPickerViewDataSource
协议。现在您应该将这些类绑定到您的
UIPickerView
。最简单的解决方案是将每个数据源的实例变量添加到UIViewController
中,初始化它们并分配给UIPickerView
的dataSource
属性。You need to create two classes for your data sources. They obviously should be derived from
NSObject
and implementUIPickerViewDataSource
protocol.Now you should bound these classes to your
UIPickerView
. The easiest solution is to add instance variables for each data source toUIViewController
, initialize them and assign todataSource
property ofUIPickerView
.