多个UIPickerViews [英] Multiple UIPickerViews
问题描述
UIPickerView
,并通过加载数组和所有其他 UIPickerView
操作来实现和运行在ViewController内。 我以为可以像新的 UIPickerView
一样复制/粘贴相同的方法,但只是更改变量名称也在同一个 UIViewController
中。
问题是 - UIPickerView
在下拉列表中显示相同的数据集?我只是在这里忘了一些明显的东西吗?
以下更新
我对下面所有四种方法都这样做了,一旦加载了下一个视图,应用程序会崩溃?这样吗?
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView
- (NSInteger)thePickerView :( UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)组件
- (NSString *)thePickerView:(UIPickerView *)thePickerView titleForRow :( NSInteger)行forComponent:(NSInteger)组件
- (void)thePickerView:(UIPickerView *)thePickerView didSelectRow :( NSInteger)行inComponent:(NSInteger)组件
是的,您必须使用UIPickerView参数来确定WHICH选择器视图实际上是要求数据 - 因为您已将两个选择器都设置为相同的数据源。
- (void)numberOfComponentInPickerView :( UIPickerView *)thePickerView {
if(thePickerView == firstPickerView){
//返回第一个选择器中的组件数
} else if(thePickerView == secondPickerView){
// return第二个选择器中的组件数
} else {
assert(NO);
}
}
//重复所有其他委托/数据源方法
I have a dilemma, I have two UIPickerViews which "show" when two distinct views load. I started with one UIPickerView
and was able to get that up and running by loading the array and all the other UIPickerView
actions within the ViewController.
I thought it would be as simple as copy/pasting the same methods for the new UIPickerView
, but just changing the variable names, also within the same UIViewController
.
Problem is - both UIPickerView
are showing the same data set in the drop down ? Am I simply missing something obvious here?
Updated below
I did that for all four methods below and now that app crashes once the "next" view is loaded? Does this look right?
- (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
Yeah you are, you have to use the UIPickerView argument to determine WHICH picker view is actually asking for data - since you have set both pickers to the same data source.
-(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
这篇关于多个UIPickerViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!