如何继承UIApplication而不是NSObject

发布于 2024-10-07 03:57:36 字数 372 浏览 0 评论 0原文

我有 3 个 Xcode 项目,我想将它们集成到一个项目中。其中两个项目是基于视图的应用程序,因此应用程序委托继承了 NSObject 和 UIApplicationDelegate。但第三个项目不是基于视图的应用程序,因此应用程序委托继承了 UIApplication。

所以现在我陷入了困境。我应该如何整合它们三个,因为如果我尝试让我的第三个类继承 NSObject 则会出现很多错误。即使我处理这些错误,应用程序也会在运行时崩溃,出现异常:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“只能有一个 UIApplication 实例。”

那我现在该怎么办?

I have three Xcode projects and I want to integrate them into one project. Two of those projects are view based application, hence the application delegate has inherited NSObject and UIApplicationDelegate. But the third project is not a view based application and so the app delegate has inherited UIApplication.

So now I am in a fix. How should I integrate the three of them, because if I try to make my third class inherit NSObject then there are many errors. And even if I deal with those errors, the app crashes during run time giving the exception:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'There can only be one UIApplication instance.'

So what do I do now?

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

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

发布评论

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

评论(1

素手挽清风 2024-10-14 03:57:36

您不应该继承 UIApplicationDelegate,而应该实现 UIApplicationDelegate 协议。

例子:

@interface SampleAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    MainViewController *mainViewController;
}

You shouldn't be inheriting from UIApplicationDelegate, but instead implementing the UIApplicationDelegate protocol.

Example:

@interface SampleAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    MainViewController *mainViewController;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文