文件所有者和 nsapplication、appdelegate [英] Files owner and nsapplication, appdelegate
问题描述
在苹果文档中,它指出 nsapplication 是主笔尖的文件所有者.这个是模板自己设置的还是必须要加载的第一个笔尖,就这样加载?
In the apple docs it states that nsapplication is the file owner of the main nib. Is this just set up by the template or must the first nib to be loaded, be loaded in this way?
此外,我通读了有关文件所有者的其余帖子,但仍然让我感到困惑.如果 Iboutlet 是 nibs 文件所有者的属性,并且在该 nib 中找到该对象,则 IBoutlets 能否仅指向对象?为什么笔尖甚至需要知道它的所有者除了对象的类?知道或不知道会启用或禁用什么?
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? 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?
另外,appdelegate 适合这张图片的什么地方?您甚至可以更改应用委托吗?
One more, where does the appdelegate fit into this picture? Can you even change the app delegate?
谢谢:-)
推荐答案
Xcode 的应用程序模板设置 MainMenu.xib
以 NSApp
作为其所有者进行加载.这是由 NSApplicationMain
函数完成的.NSApplicationMain
在应用程序的 Info.plist
文件中查找 NSMainNibFile
键.如果找到该键,则使用相应的值作为要加载的 nib 文件的名称.Xcode 的应用程序模板将 NSMainNibFile
设置为 MainMenu
.
Xcode's application template sets up MainMenu.xib
to be loaded with NSApp
as its owner. This is done by the NSApplicationMain
function. NSApplicationMain
looks up the NSMainNibFile
key in the app's Info.plist
file. If it finds that key, it uses the corresponding value as the name of the nib file to load. Xcode's app template sets NSMainNibFile
to MainMenu
.
不必那样做.您可以更改或删除 Info.plist
中的 NSMainNibFile
条目.你甚至可以不使用NSApplicationMain
.相反,您可以自己初始化 NSApp
(通过调用 [NSApplication sharedApplication]
),然后以编程方式或通过加载笔尖创建用户界面,然后调用 [NSApp run]
.
It doesn't have to be done that way. You can change or delete the NSMainNibFile
entry in Info.plist
. You could even not use 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]
.
nib 加载器只能将 outlet 连接到它正在加载的 nib 中的对象,或者连接到文件的所有者、第一响应者或应用程序.出口本身不必在文件所有者上;它可以在笔尖中的任何物体上.
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.
当您设置文件所有者的类时,Interface Builder 会扫描您的源代码以查找该类的声明.这就是它如何知道文件所有者应该拥有哪些出口和操作.
When you set the class of File's owner, Interface Builder scans your source code to find the declaration of that class. That's how it knows which outlets and actions File's Owner should have.
应用程序委托通常是应用程序的顶级控制器.当各种应用程序级事件发生时,它会收到通知.查看 NSApplicationDelegate 协议参考.
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.
在 Xcode 的应用程序模板中,应用程序委托是 MainMenu.xib
中的一个对象(您可以在 nib 中拥有非用户界面对象),它连接到文件所有者的 委托
出口.您可以根据需要修改该类.您甚至可以完全从笔尖中删除对象.但任何严肃的应用都需要一个应用委托.
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. 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.
这篇关于文件所有者和 nsapplication、appdelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!