当在可可项目中按下按钮时,如何使 UIPickerView 更改值?
我正在运行 xcode 4.3,并且想知道如何让 UIPickerView 在按下同一视图上的按钮时更改其值。请发布一些与选择器更改相关的代码,因为我知道如何将其实现到按钮中。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我正在运行 xcode 4.3,并且想知道如何让 UIPickerView 在按下同一视图上的按钮时更改其值。请发布一些与选择器更改相关的代码,因为我知道如何将其实现到按钮中。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
想必您的选择器是通过数组或类似的方式填充的?
如果是这样,则让按钮更改数组的内容,然后调用
[myPickerView reloadAllComponents];
。Presumably your picker is being populated via an Array or similar?
If so then have the button change the contents of the array and then call
[myPickerView reloadAllComponents];
.我认为您只需要
UIPickerView
的reloadAllComponents
方法。因此,在按钮操作方法中,请按照以下步骤操作:更改
UIPickerViewDelegate
返回的数据。即更改您在pickerView:titleForRow:forComponent:
中使用的任何对象以返回该行的标题。在
UIPickerView
上调用reloadAllComponents
。I think you just want
UIPickerView
'sreloadAllComponents
method. So in the button action method, follow these steps:Change the data that is returned by your
UIPickerViewDelegate
. i.e. change whatever object it is you're using withinpickerView:titleForRow:forComponent:
to return the title for that row.Call
reloadAllComponents
on yourUIPickerView
.