Iphone 多个UIPickerViews
我左右为难,我有两个UIPickerViews,当加载两个不同的视图时“显示”。我从一个Iphone 多个UIPickerViews,iphone,ios,dataset,uipickerview,uipicker,Iphone,Ios,Dataset,Uipickerview,Uipicker,我左右为难,我有两个UIPickerViews,当加载两个不同的视图时“显示”。我从一个UIPickerView开始,通过在ViewController中加载数组和所有其他UIPickerView操作,我能够启动并运行它 我认为这很简单,只需为新的UIPickerView复制/粘贴相同的方法,只需更改变量名,也可以在相同的UIViewController中更改 问题是-两个UIPickerView都在下拉列表中显示相同的数据集?我只是错过了一些明显的东西吗 更新如下 我在下面的四种方法中都这么做
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视图实例。是的,这些方法看起来不错,崩溃是由其他原因造成的。试试调试器!在运行->调试器时。或者发布更多代码。