问题描述
我正在使用情节提要开发一个 iOS5 应用程序,并且我在视图控制器类中有一个方法,我想从 App Delegate 访问该方法.问题是,这个视图控制器是通过故事板中的标签栏控制器实例化的,所以 App Delegate 无法直接调用我想要的方法......
I'm working on an iOS5 app using storyboard, and I have a method in a view controller class that i'd like to access from the App Delegate. The trouble is, this view controller gets instantiated via a tab bar controller in storyboard, so the App Delegate has no direct way of calling the method I want...
要让视图控制器与 App Delegate 取得联系,只需使用:
For a view controller to get in touch with the App Delegate, all one has to do is use:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
是否有类似的简单方法可以指向已经实例化的视图控制器或类?
Is there a similarly easy way of pointing to an already-instantiated view controller or class?
推荐答案
您必须从应用委托遍历视图层次结构.假设 AppDelegate 包含对 UITabBarController 的引用,您可以使用 viewControllers 属性或 selectedViewController 属性来获取你的视图控制器.
You'll have to traverse the view hierarchy from the app delegate. Assuming the AppDelegate holds a reference to the UITabBarController, you could use the viewControllers property or selectedViewController property to get to your view controller.
这篇关于使用 App Delegate 访问通过 Storyboard 创建的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)