如何将应用程序委托添加回mainwindow.xib [英] How to add app delegate back to mainwindow.xib

查看:185
本文介绍了如何将应用程序委托添加回mainwindow.xib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简答案

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

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

详细信息请看下面的答案。

Details see the answer below.

我不小心从mainwindow.xib中删除了应用程序委托。我看到无处不在,但仍然找不到一种方法来添加它。我试图在网上找到它,仍然没有结果。任何人都可以帮我解决吗?谢谢。

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.

我的项目

其他项目

Main.m

#import <UIKit/UIKit.h>

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


推荐答案

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

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.

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

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]));
    }
}

...但是如果您的应用程序有一个MainWindow.xib,上述都是不正确的,并且您想在MainWindow.xib中创建一个AppDelegate的实例。为此,只需将通用Object从Object Library拖到对象区域在IB, d然后转到身份检查器,并将Class字段设置为App代理的类名。 (您可以从View / Utilities获取对象库和身份检查器。

…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.

这篇关于如何将应用程序委托添加回mainwindow.xib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆