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

发布于 2024-12-27 11:58:31 字数 74 浏览 0 评论 0原文

谁能告诉我如何在另一个视图中显示 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

财迷小姐 2025-01-03 11:58:31

通常,当用户关闭第二个视图时,您会将值数据存储在模型中。当模型重新出现时(或使用通知),第一个视图将从模型中读取值。您的模型数据可以是 plist、nsuserdefaults 或 core-data 等。

或者,您可以在创建第二个 viewController 时创建对第一个 viewController 的引用,并将其分配为第二个 viewController 上的属性。那么第二个 viewController 实际上有一个到第一个 viewController 的“路径”:

第一个 viewController 将有一个属性,例如:

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

第二个 viewController 将有一个属性,例如:

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

当您创建第二个 viewController 时,您将执行以下操作:

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

然后当你想更新第一个 ViewController 中的 myStr (从第二个 viewController )你会这样做:

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

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:

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:

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:

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:

firstVC = @" my new value ";  // in the implementation file
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文