Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 多个UIPickerViews_Iphone_Ios_Dataset_Uipickerview_Uipicker - Fatal编程技术网

Iphone 多个UIPickerViews

Iphone 多个UIPickerViews,iphone,ios,dataset,uipickerview,uipicker,Iphone,Ios,Dataset,Uipickerview,Uipicker,我左右为难,我有两个UIPickerViews,当加载两个不同的视图时“显示”。我从一个UIPickerView开始,通过在ViewController中加载数组和所有其他UIPickerView操作,我能够启动并运行它 我认为这很简单,只需为新的UIPickerView复制/粘贴相同的方法,只需更改变量名,也可以在相同的UIViewController中更改 问题是-两个UIPickerView都在下拉列表中显示相同的数据集?我只是错过了一些明显的东西吗 更新如下 我在下面的四种方法中都这么做

我左右为难,我有两个UIPickerViews,当加载两个不同的视图时“显示”。我从一个
UIPickerView
开始,通过在ViewController中加载数组和所有其他
UIPickerView
操作,我能够启动并运行它

我认为这很简单,只需为新的
UIPickerView
复制/粘贴相同的方法,只需更改变量名,也可以在相同的
UIViewController
中更改

问题是-两个
UIPickerView
都在下拉列表中显示相同的数据集?我只是错过了一些明显的东西吗

更新如下

我在下面的四种方法中都这么做了,现在应用程序在“下一个”视图加载后崩溃了?这个看起来对吗

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView 

- (NSInteger)thePickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component

- (NSString *)thePickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

- (void)thePickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

是的,您必须使用UIPickerView参数来确定哪个选择器视图实际请求数据-因为您已将两个选择器设置为相同的数据源

-(void)numberOfComponentInPickerView:(UIPickerView*)thePickerView {
    if(thePickerView == firstPickerView) {
       // return number of components in first picker    
    } else if(thePickerView == secondPickerView) {    
       // return number of components in second picker    
    } else {
       assert(NO);
    }
}

// repeat for all other delegate / datasource methods

哈哈-是的,格式化很难-给我一分钟!更新,谢谢我想知道我是否需要初始化“thePickerView”?如果是,我是否应该将IB中的UIPickerView与“thePickerView”和“Second PickerView”关联?例如,否,应设置thePickerView-请求数据的是picker视图-无picker视图,无请求数据。将选择器视图设置为IBOutlet,并在xib中连接它们。如果仍然存在问题,可以创建两个类-每个picker视图一个数据源,然后在viewDidLoad方法中将它们手动分配给picker视图实例。是的,这些方法看起来不错,崩溃是由其他原因造成的。试试调试器!在运行->调试器时。或者发布更多代码。