如何将应用程序委托添加回 mainwindow.xib

发布于 2025-01-04 10:17:13 字数 593 浏览 5 评论 0原文

简短回答:

从对象库中拖动一个对象并将其类设置为委托。

详情请看下面的回答。

我不小心从 mainwindow.xib 中删除了应用程序委托。我查遍了所有地方,但仍然找不到将其添加回来的方法。我试图在网上找到它,但仍然没有结果。谁能帮我解决它吗?谢谢。

我的项目

我的项目

其他人的项目

其他项目,有 appdelegate

Main.m

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, nil);
    }
}

short answer:

drag a Object from Object library and set its class to delegate.

Details see the answer below.

I accidentally removed app delegate from mainwindow.xib. I looked into everywhere but still cannot find a way to add it back. I tried to find it online and still got no result. Can anyone help me to fix it? Thank you.

My project

My project

Other's project

Other's project, which has appdelegate

Main.m

#import <UIKit/UIKit.h>

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, nil);
    }
}

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

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

发布评论

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

评论(1

舂唻埖巳落 2025-01-11 10:17:13

通常,您的 AppDelegate 不会在任何 .xib 文件中引用。相反,您的 main.m 将实例化 AppDelegate 的一个实例(通过 UIApplicationMain 函数),然后您的 AppDelegate 将实例化一个或多个视图控制器,这反过来又会取消存档一些基于 . xib 文件。

main.m 中您的应用程序的入口点(您的 AppDelegate 在其中实例化并启动您的应用程序)应如下所示(如果您的应用程序委托有不同的类名,请使用它而不是 AppDelegate

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

...但是如果您的应用程序有 MainWindow.xib,则上述内容都是不正确的,并且您确实希望在 MainWindow.xib 中创建 AppDelegate 的实例,只需从其中拖动一个通用对象即可。将对象库放入IB 中的对象区域,然后转到身份检查器并将类字段设置为应用程序委托的类名称(您可以从视图/实用程序访问对象库和身份检查器)。

Typically your AppDelegate won't be referenced in any .xib files. Rather, your main.m will instantiate an instance of AppDelegate (via the UIApplicationMain function), and then your AppDelegate will instantiate one or more of your view controllers, which in turn will unarchive some views based on .xib files.

The entry point for your app in main.m, where your AppDelegate gets instantiated and starts up your app, should look like this (If your app delegate has a different class name, use that instead of AppDelegate:

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

…But if your application has a MainWindow.xib, the above is all incorrect, and you do want to make an instance of your AppDelegate in MainWindow.xib. To do that, just drag a generic Object from the Object Library into the Objects area in IB, and then go to the Identity Inspector and set the Class field to the class name of your App Delegate. (You can get to the Object Library and Identity Inspector from View/Utilities.

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