我正在使用情节提要开发一个 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模板网!
如何通过点击动画 UIImageview 以显示全屏?How to animate a UIImageview to display fullscreen by tapping on it?(如何通过点击动画 UIImageview 以显示全屏?)
停止 segue 并显示警报To stop segue and show alert(停止 segue 并显示警报)
iOS 5 故事板,以编程方式确定路径iOS 5 storyboard, programmatically determine path(iOS 5 故事板,以编程方式确定路径)
UIProgressView 和自定义跟踪和进度图像(iOS 5 属性UIProgressView and Custom Track and Progress Images (iOS 5 properties)(UIProgressView 和自定义跟踪和进度图像(iOS 5 属性))
语义问题:属性的合成 getter 遵循 Cocoa 命名约定以Semantic Issue: Property#39;s synthesized getter follows Cocoa naming convention for returning #39;owned#39; objects(语义问题:属性的合成 gette
自定义字体在我的应用程序中不起作用?Custom font is not working in my App?(自定义字体在我的应用程序中不起作用?)