Xcode 如何决定首先显示哪个 XIB
当我在 Xcode 中创建一个新的 cocoa 项目时,它会创建一个带有窗口的 MainMenu.xib 文件。我想将窗口分成 MainWindow.xib 并将其显示为主窗口 - 我该怎么做?
如果我创建一个基于“文档”的应用程序 - 我会看到两个 xib(MainMenu.xib 和 MyDocument.xib),并且我注意到 MyDocument.xib 立即显示 - 但我不明白这是在哪里标识的。似乎没有明确的代码,我不知道在 plist 中查找哪里。
如果我创建一个新文档,如何使其成为启动应用程序时显示的主窗口?
When I create a new cocoa project in Xcode, it creates a MainMenu.xib file with a Window. I would like to separate the window into a MainWindow.xib and have that show up as the main window - how do I do that?
If I create a 'document' based application - I see two xibs (MainMenu.xib and MyDocument.xib) and I notice that MyDocument.xib gets displayed right away - but I don't understand where this is identified. There doesn't seem to be explicit code and I'm not sure where to look in the plists.
If I create a new Document, how can I make it the primary window that shows up when I start the app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
-Info.plist
中,您将找到键“Main nib file base name”,其中第一个要加载的 xib 的值通常为“MainMenu”。您还会发现“文档类型”-> “项目 0”-> “Cocoa NSDocument Class”并且有值“MyDocument”。在“MyDocument”类中,有一个方法
- (NSString *)windowNibName
。这将返回要加载的第一个 xib 的名称。in
<YourProjectName>-Info.plist
you'll find the key "Main nib file base name", with the value of the first xib to load usually "MainMenu".Also you'll find "Document types" -> "Item 0" -> "Cocoa NSDocument Class" and there the value "MyDocument". In the class "MyDocument" there is a method
- (NSString *)windowNibName
. This return the name of the first xib to load.窗口管理是您的责任。不要依赖框架以任何顺序显示窗口,因为该顺序是未定义的。
首先,确保在 Interface Builder 中为您的窗口未选中
启动时可见
复选框。如果是这样,您将无法有效地控制窗口显示。默认情况下它是打开的。接下来,为要加载的每个窗口笔尖使用
NSWindowController
子类。然后,在主应用程序控制器中,您可以控制何时实例化这些NSWindowController
对象以及何时调用它们的-showWindow
方法。在您的示例中,您可能会在应用程序委托的
-applicationDidFinishLaunching:
方法中实例化MainWindow.xib
的NSWindowController
。Window management is your responsibility. Don't rely on the frameworks to display windows in any order, as that order is undefined.
Firstly, make sure that the
Visible at Launch
checkbox is not checked for your windows in Interface Builder. If it is, you won't be able to control window display effectively. It's on by default.Next, use an
NSWindowController
subclass for each window nib that you want to load. Then, in your main application controller you can control when thoseNSWindowController
objects are instantiated and when to call their-showWindow
methods.In your example case, you'd probably instantiate the
NSWindowController
for yourMainWindow.xib
in the‑applicationDidFinishLaunching:
method in your application delegate.