如何从另一个视图控制器访问一个视图控制器中的变量? [英] How do I access a variable in one view controller from another view controller?

查看:95
本文介绍了如何从另一个视图控制器访问一个视图控制器中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的UINavtigationController应用程序中,我有一个用户在UITableViewController中选择一个值,一旦完成,它们将被发送回之前必须显示该值的UITableViewController。我期待的问题是,一旦视图被弹出,我假设它的viewUnload被调用,摆脱了数组,使得它在另一个视图控制器中无法访问。

In my UINavtigationController application, I have a user select a value in UITableViewController and once that is done, they are sent back to a previous UITableViewController where that value must be shown. The problem I am anticipating is that once a view is "popped", I am assuming that its viewUnload is called that gets rid of the array making it unaccessible in another view controller.

有什么想法吗?

推荐答案

你需要传递新值通过使用任何方法从didSelectRowIndex函数中的上一个控制器

You need to pass the new value to previous controller from your didSelectRowIndex function by using anyone of the approaches

1 - > 使用 NSUserDefault

iPhone编程教程 - 使用NSUserDefaults保存/检索数据

2 - > 使用委派概念。

3 - > 您也可以从 ViewController /ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html\"rel =nofollow noreferrer> UINavigationController 方法。

3-> you could also access the previous ViewController from you UINavigationController methods.

这篇关于如何从另一个视图控制器访问一个视图控制器中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆