How to add app delegate back to mainwindow.xib

对着背影说爱祢 提交于 2019-12-22 13:07:09

问题


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

Other's project

Main.m

#import <UIKit/UIKit.h>

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

回答1:


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.



来源:https://stackoverflow.com/questions/9206502/how-to-add-app-delegate-back-to-mainwindow-xib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!