多个 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,您必须使用 UIPickerView 参数来确定哪个选择器视图实际上正在请求数据 - 因为您已将两个选择器设置为相同的数据源。
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.