问题描述
我正在编写我的第一个 iPhone 应用程序,但在切换视图时遇到了问题.我在 AppDelegate(UIApplicationDelegate 的一个实例)中有 2 个视图和对每个视图的引用.我在 applicationDidFinishLaunching 中创建了这两个实例并立即显示第一个视图.这工作正常.
I'm writing my first iPhone application and I'm having trouble switching views. I have 2 views and a reference to each in the AppDelegate (an instance of UIApplicationDelegate). I create instances of both in the applicationDidFinishLaunching and immediately show the first view. This works fine.
问题是对另一个视图的引用在 AppDelegate 中,我不知道如何获取对它的引用,因此我可以切换到另一个视图.有没有办法获得对主要 UIApplication 或 UIApplicationDelegate 对象的引用?
The problem is the reference to the other view is in the AppDelegate and I can't figure out how to get a reference to it so I can switch to the other view. Is there a way to get a reference to the main UIApplication or UIApplicationDelegate objects?
推荐答案
是的,UIApplication 是一个单例,并且使用了 Objective-C 的普通单例模式:
Yes, UIApplication is a singleton, and uses the normal singleton pattern for Objective-C:
[UIApplication sharedApplication];
您可以直接从中获取您的委托类:
You can get your delegate class directly from it:
MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
这篇关于获取对 UIApplication 委托的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


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