多个 UIPickerView

发布于 2024-10-30 08:52:18 字数 832 浏览 7 评论 0原文

我遇到了一个困境,我有两个 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌︼了一个春 2024-11-06 08:52:18

是的,您必须使用 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文