如何将应用程序委托添加回 mainwindow.xib
简短回答:
从对象库中拖动一个对象并将其类设置为委托。
详情请看下面的回答。
我不小心从 mainwindow.xib 中删除了应用程序委托。我查遍了所有地方,但仍然找不到将其添加回来的方法。我试图在网上找到它,但仍然没有结果。谁能帮我解决它吗?谢谢。
我的项目
其他人的项目
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
Other's project
Main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, nil);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您的 AppDelegate 不会在任何 .xib 文件中引用。相反,您的 main.m 将实例化 AppDelegate 的一个实例(通过 UIApplicationMain 函数),然后您的 AppDelegate 将实例化一个或多个视图控制器,这反过来又会取消存档一些基于 . xib 文件。
main.m
中您的应用程序的入口点(您的 AppDelegate 在其中实例化并启动您的应用程序)应如下所示(如果您的应用程序委托有不同的类名,请使用它而不是AppDelegate
:...但是如果您的应用程序有 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 ofAppDelegate
:…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.