Accessing a view controller created through Storyboard using the App Delegate(使用 App Delegate 访问通过 Storyboard 创建的视图控制器)
问题描述
我正在使用情节提要开发一个 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 创建的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 App Delegate 访问通过 Storyboard 创建的视图控制


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 拆分 Drawable 2022-01-01