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 委托的引用


基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01