如何在 UIPickerView 中选择行
我有一个 UIPickerView 有两个组件。组件 1 中的行数取决于组件 0。我正在尝试以下操作:
// [picker reloadAllComponents];
[picker selectRow:5 inComponent:0 animated:NO];
[picker reloadComponent:1]; // [picker reloadAllComponents];
[picker selectRow:3 inComponent:1 animated:NO];
// [picker reloadAllComponents];
发生的情况是组件 0 设置为索引 5,而组件 1 显示信息,就好像在组件 0 中选择了索引 0 一样!
I have a UIPickerView that has two components. The number of rows in component 1 depends on component 0. I am trying the following:
// [picker reloadAllComponents];
[picker selectRow:5 inComponent:0 animated:NO];
[picker reloadComponent:1]; // [picker reloadAllComponents];
[picker selectRow:3 inComponent:1 animated:NO];
// [picker reloadAllComponents];
What happens is that component 0 is set to index 5 and component 1 is showing the info as if index 0 was selected in component 0!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我尝试了完全相同的事情,效果非常好。以下是一些相关代码:
此代码仅在您手动选择行时才相关:
我添加了一个按钮,在点击该按钮时执行您的代码。
这是我拥有的最后一段相关代码:
一切都按预期工作,因此您发布的行不是导致问题的行。如果您在阅读我的代码(经过测试且有效)后仍无法弄清楚,我建议您发布更多代码。
I tried the exact same thing and it works perfectly. Here's some relevant code:
This code is only relevant if you select the row manually:
I added a button that executes your code when it's tapped.
Here's the last relevant piece of code that I have:
Everything works as expected, so the lines you posted aren't the ones causing the problem. If you can't figure it out after having read my code (that is tested and working) I suggest you post some more code.