获取对 UIApplication 委托的引用

发布于 2024-07-29 06:57:32 字数 365 浏览 4 评论 0原文

我正在编写我的第一个 iPhone 应用程序,但在切换视图时遇到问题。 我有 2 个视图以及对 AppDelegate 中每个视图的引用(UIApplicationDelegate 的实例)。 我在 applicationDidFinishLaunching 中创建了这两个实例,并立即显示第一个视图。 这很好用。

问题是对另一个视图的引用位于 AppDelegate 中,我不知道如何获取对它的引用,以便我可以切换到另一个视图。 有没有办法获取对主要 UIApplicationUIApplicationDelegate 对象的引用?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天煞孤星 2024-08-05 06:57:32

是的,UIApplication 是一个单例,并且使用 Objective-C 的普通单例模式:

[UIApplication sharedApplication];

您可以直接从中获取委托类:

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

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];
当爱已成负担 2024-08-05 06:57:32

使用:

[[UIApplication sharedApplication] delegate];

Use:

[[UIApplication sharedApplication] delegate];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文