简体   繁体   English

文件所有者和nsapplication,appdelegate

[英]Files owner and nsapplication, appdelegate

In the apple docs it states that nsapplication is the file owner of the main nib. 在apple docs中,它声明nsapplication是主要笔尖的文件所有者。 Is this just set up by the template or must the first nib to be loaded, be loaded in this way? 这是由模板设置的,还是必须以这种方式加载第一个笔尖?

Also, I read through the rest of the posts about the file owner and something still confuses me. 另外,我通读了有关文件所有者的其余帖子,但仍然使我感到困惑。 Can IBoutlets only point to objects, if the Iboutlet is a property of the nibs file owner, and the object is found within that nib? 如果Iboutlet是nibs文件所有者的属性,并且该对象位于该nib中,则IBoutlet只能指向对象吗? Why does the nib even need to know the class of it's owner In addition to the object? 为什么笔尖除了对象之外,甚至还需要知道其所有者的类? What is enabled or disable by knowing or not knowing this? 通过了解或不知道启用或禁用了什么?

One more, where does the appdelegate fit into this picture? 再说一次,appdelegate在哪里适合这张图片? Can you even change the app delegate? 您甚至可以更改应用程序委托吗?

Thanks :-) 谢谢 :-)

Xcode's application template sets up MainMenu.xib to be loaded with NSApp as its owner. Xcode的应用程序模板将MainMenu.xib设置为以NSApp作为其所有者加载。 This is done by the NSApplicationMain function. 这是通过NSApplicationMain函数完成的。 NSApplicationMain looks up the NSMainNibFile key in the app's Info.plist file. NSApplicationMain在应用程序的Info.plist文件中查找NSMainNibFile键。 If it finds that key, it uses the corresponding value as the name of the nib file to load. 如果找到该密钥,它将使用相应的值作为要加载的nib文件的名称。 Xcode's app template sets NSMainNibFile to MainMenu . Xcode的应用程序模板将NSMainNibFile设置为MainMenu

It doesn't have to be done that way. 不必那样做。 You can change or delete the NSMainNibFile entry in Info.plist . 您可以更改或删除Info.plistNSMainNibFile条目。 You could even not use NSApplicationMain . 您甚至不能使用NSApplicationMain Instead you could initialize NSApp yourself (by calling [NSApplication sharedApplication] ), and then create your user interface programmatically or by loading nibs, and then call [NSApp run] . 相反,您可以自己初始化NSApp (通过调用[NSApplication sharedApplication] ),然后以编程方式或通过加载笔尖创建用户界面,然后调用[NSApp run]

The nib loader can only connect outlets to objects in the nib it's loading, or to File's Owner, First Responder, or Application. 笔尖加载器只能将插座连接到正在加载的笔尖中的对象,或者连接到文件的所有者,第一响应者或应用程序。 The outlet itself doesn't have to be on File's Owner; 出口本身不必位于文件的所有者上; it can be on any object in the nib. 它可以在笔尖上的任何对象上。

When you set the class of File's owner, Interface Builder scans your source code to find the declaration of that class. 当您设置文件所有者的类时,Interface Builder会扫描您的源代码以查找该类的声明。 That's how it knows which outlets and actions File's Owner should have. 这样一来,它便知道File Owner应该拥有哪些出口和行动。

The app delegate is generally the top-level controller for the application. 应用程序委托通常是应用程序的顶级控制器。 It is notified when a variety of application-level events occur. 当发生各种应用程序级别的事件时,它会得到通知。 Look at the NSApplicationDelegate Protocol Reference . 查看NSApplicationDelegate协议参考

In Xcode's app template, the application delegate is an object in MainMenu.xib (you can have non-user-interface objects in a nib), which is wired to File Owner's delegate outlet. 在Xcode的应用程序模板中,应用程序委托是MainMenu.xib一个对象(您可以在笔尖中包含非用户界面对象),该对象已连接到文件所有者的delegate出口。 You can modify the class however you want. 您可以根据需要修改类。 You can even delete the object from the nib entirely. 您甚至可以从笔尖完全删除对象。 But any serious app will need an app delegate. 但是,任何严肃的应用程序都需要一个应用程序委托。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM