一个视图中有多个PickerView? [英] Multiple PickerViews in one View?

查看:88
本文介绍了一个视图中有多个PickerView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用相同的viewController在同一视图中创建2个单独的选择器。
但是如何为它们设置单独的委托和数据源?

I want to create 2 separate pickers in the same view using the same viewController. But how do I set separate delegates and datasource for them?

似乎无法使其正常工作。它们显示相同的数据。如果您有任何示例代码,我们将不胜感激。

Can't seem to get it working. They show up with the same data. If you have any sample code on this it will be much appreciated.

谢谢。

推荐答案

请注意,数据源和委托协议的每个方法都包含 UIPickerView * 参数,例如:

Note that each method of both the datasource and the delegate protocols contain a UIPickerView * parameter, for instance:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

您需要使用它来区分您的两个实例,如下所示:

You need to use it to distinguish between your two instances, as follows:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{

    if([pickerView isEqual: pickerOne]){
      // return the appropriate number of components, for instance
         return 3;
    }

    if([pickerView isEqual: pickerTwo]){
      // return the appropriate number of components, for instance
         return 4;
    }
}

这篇关于一个视图中有多个PickerView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆