简体   繁体   English

如何将选定的值从uipickerview显示到另一个视图

[英]How can I show the selected value from uipickerview to anotherview

Can anyone tell me how can I show the value from one a UIPickerView in another view? 谁能告诉我如何在另一个视图中显示一个UIPickerView的值? I am storing a value in a label but I have to show this value in a button in another view controller. 我将值存储在标签中,但必须在另一个视图控制器的按钮中显示该值。

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. 您的模型数据可以是plist或nsuserdefaults或core-data等。

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. 另外,您可以在创建第二个viewController时创建对第一个viewController的引用,并将其分配为第二个viewController的属性。 Then the second viewController in effect has a "path" to the first viewController: 然后,第二个viewController实际上具有到第一个viewController的“路径”:

The first viewController would have a property such as: 第一个viewController将具有以下属性:

NSString *myStr;  // in the header
@property (nonatomic, retain) NSString *myStr;  // in the header file
@synthesize myStr;  // in the implementation file

The second viewController would have a property such as: 第二个viewController将具有以下属性:

firstViewController *firstVC;  // in the header
@property (nonatomic, retain) firstViewController *firstVC;  // in the header file
@synthesize firstVC;  // in the implementation file

When you create the second viewController you would do something like: 创建第二个viewController时,您将执行以下操作:

secondViewController.firstVC = self;  // in the implementation file

Then when you want to update myStr in the first ViewController (from the second viewController) you would do something like: 然后,当您想在第一个ViewController中(从第二个ViewController中)更新myStr时,您将执行以下操作:

firstVC = @" my new value ";  // in the implementation file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM