如何将 uipickerview 中的选定值显示到另一个视图
谁能告诉我如何在另一个视图中显示 UIPickerView 的值?我正在标签中存储一个值,但我必须在另一个视图控制器的按钮中显示该值。
Can anyone tell me how can I show the value from one a UIPickerView in another view? I am storing a value in a label but I have to show this value in a button in another view controller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,当用户关闭第二个视图时,您会将值数据存储在模型中。当模型重新出现时(或使用通知),第一个视图将从模型中读取值。您的模型数据可以是 plist、nsuserdefaults 或 core-data 等。
或者,您可以在创建第二个 viewController 时创建对第一个 viewController 的引用,并将其分配为第二个 viewController 上的属性。那么第二个 viewController 实际上有一个到第一个 viewController 的“路径”:
第一个 viewController 将有一个属性,例如:
第二个 viewController 将有一个属性,例如:
当您创建第二个 viewController 时,您将执行以下操作:
然后当你想更新第一个 ViewController 中的 myStr (从第二个 viewController )你会这样做:
Typically you would store the value data in your model when the user closes the second view. and the first view would read the value from the model when it re-appears (or use notifications). Your model data could be a plist, or nsuserdefaults or core-data etc.
Alternatively you could create a reference to the first viewController when you create your second viewController and assign this as a property on the second viewController. Then the second viewController in effect has a "path" to the first viewController:
The first viewController would have a property such as:
The second viewController would have a property such as:
When you create the second viewController you would do something like:
Then when you want to update myStr in the first ViewController (from the second viewController) you would do something like: