Xcode:UIPickerView 文本 &查看控制器链接
我在 XCode 中创建了两个视图控制器以及一个 UIPickerView、一个标签、一个文本视图。我想尝试从 UIPickerView 获取数据,因此当应用程序检测到已选择一行时,它会自动将标签设置为 UIPickerView 中该行的值。我还想要某些选定行的某些描述。
请在此处查看我的应用程序的一些屏幕截图,以进一步了解我正在尝试做什么;
1) http://cl.ly/102K3p2v433N0F1c0m2i - 主屏幕
2) http://cl.ly/102K3p2v433N0F1c0m2i - 控制杆被“拉动”后选定的行
3) http://cl.ly/2d1D2D1Z1s0k053Z2C3H - 弹出视图控制器,但标签/描述仍然具有默认值
这是我的代码;
1) (主屏幕) TroubleMakerViewController.h - http://pastie.org/2466793
2) (主屏幕) TroubleMakerViewController.m - http://pastie.org/2466795
3)(结果屏幕)Results.h - http://pastie.org/2466805
4)(结果屏幕)结果.m - http://pastie.org/2466808
有人可以解释为什么标签和描述文本显示默认文本而不是我的内容有设置吗? XIB 文件中的所有内容都正确链接。
I have created two view controllers in XCode along with a UIPickerView, a label, a text view. I wanted to try and get data from the UIPickerView, so when the app detects that a row has been selected, it will automatically set the label to the value of the row in the UIPickerView. I also wanted certain descriptions for certain selected rows.
See some screenshots of my app here to further understand what it is I am trying to do;
1) http://cl.ly/102K3p2v433N0F1c0m2i - main screen
2) http://cl.ly/102K3p2v433N0F1c0m2i - selected row after lever has been "pulled"
3) http://cl.ly/2d1D2D1Z1s0k053Z2C3H - view controller pops up but the label/description still have default values
Here is my code;
1) (MAIN SCREEN) TroubleMakerViewController.h - http://pastie.org/2466793
2) (MAIN SCREEN) TroubleMakerViewController.m - http://pastie.org/2466795
3) (RESULTS SCREEN) Results.h - http://pastie.org/2466805
4) (RESULTS SCREEN) Results.m - http://pastie.org/2466808
Can somebody explain why the label and description text is showing the default text rather than what I have set it to do? Everything is linked up properly in the XIB files.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要实现 UIPickerViewDelegate 方法
pickerView:didSelectRow:inComponent:
,如 文档 一旦当前选定的值就会收到通知变化。在此方法中,只需更新标签的文本即可;-)You need to implement the UIPickerViewDelegate method
pickerView:didSelectRow:inComponent:
as described in the documentation to be notified as soon as the currently selected value changes. In this method just simply update the text of your label ;-)