How does Xcode decide which XIB to show first

有些话、适合烂在心里 提交于 2019-12-18 04:14:09

问题


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?


回答1:


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.




回答2:


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 those NSWindowController objects are instantiated and when to call their -showWindow methods.

In your example case, you'd probably instantiate the NSWindowControllerfor your MainWindow.xib in the ‑applicationDidFinishLaunching: method in your application delegate.



来源:https://stackoverflow.com/questions/5237833/how-does-xcode-decide-which-xib-to-show-first

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!