Cocoa:什么创建链接到 NIB 文件的控制器类的实例?
这是一个关于 Cocoa NIB 文件的内部工作原理及其支持框架类的问题。
有关方便的示例,请查看 Apple 货币计算器教程: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCTutorial/01Introduction/01Introduction.html
如果打开 MainMenu.nib 文件,您将看到代表“转换器控制器”的对象。
当应用程序运行时,ConverterController 类的实例由应用程序中的某些内容(NIB 中的某些内容或支持 NIB 的框架)实例化。
(不要将其与另一个类 Converter 混淆,后者的实例是由 ConverterController 中的代码创建的。)
我的问题是,是什么创建了 ConverterController 的这个实例?它是 NIB 中默认的文件所有者对象吗?无论对象创建实例,该对象使用的代码是什么? NIB 或框架中的某处必须有某种方法/函数说:
ConverterController *someVarName = [[ConverterController alloc] init];
我想查看该代码,当前用于创建 ConverterController 实例的特定代码。
我不想知道如何创建 ConverterController 实例的替代品,或者一般如何手动实例化与 NIB 文件相关的类实例。
This is a question about the inner workings of Cocoa NIB files and the supporting framework classes for them.
For a handy example, please take a look at the Apple Currency Calculator tutorial: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCTutorial/01Introduction/01Introduction.html
If you open the MainMenu.nib file, you will see an object representing "Converter Controller".
When the app runs, an instance of the ConverterController class is instantiated by something in the app (something in the NIB, or the framework supporting the NIB).
(Don't confuse this with the other class, Converter, which has its instance created by the code in ConverterController.)
My question is, what creates this instance of ConverterController? Is it the default File's Owner object in the NIB? Whatever object creates the instance, what is the code that that object uses? There must be some method/function somewhere in the NIB or framework saying:
ConverterController *someVarName = [[ConverterController alloc] init];
I want to see that code, the specific code that is currently being used to create the ConverterController instance.
I don't want to know how to create a replacement for the ConverterController instance, or in general how to manually instantiate class instances related to a NIB file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
笔尖是对象的档案。它们是在 Interface Builder 中创建的,当加载 nib 时,其中的对象将被取消归档并链接起来。
A nib is an archive of objects. They're created in Interface Builder, and when the nib is loaded, the objects in it are unarchived and linked up.
查看资源编程指南 开发者文档中的文档。关于 Nib 文件的部分是一个很好的概述,“对 Nib 文件的内置支持”小节解释了在多种情况下如何加载 nib 文件。
Take a look at the Resource Programming Guide document in the developer docs. The section on Nib files is a good overview, and the sub-section "Built-In Support For Nib Files" explains how nib files get loaded in a number of cases.
查看 Info.plist 文件。
其中的部分之一是主笔尖文件名。这是应用程序启动时取消归档的笔尖。通常,这是 MainMenu.xib。
由于控制器对象位于此主 nib 文件内,因此它是在 nib 文件取消归档时创建的。
Have a look at the Info.plist file.
One of the sections in there is for the Main Nib file name. This is the nib that is unarchived when the application starts. Usually, this is MainMenu.xib.
Because the controller object is within this main nib file, it is created when the nib file is unarchived.