Getting a reference to the UIApplication delegate(获取对 UIApplication 委托的引用)
问题描述
我正在编写我的第一个 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 委托的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取对 UIApplication 委托的引用
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
