Xcode 如何决定首先显示哪个 XIB

发布于 2024-10-21 01:50:11 字数 287 浏览 2 评论 0原文

当我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我鬧 2024-10-28 01:50:11

-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.

老旧海报 2024-10-28 01:50:11

窗口管理是您的责任。不要依赖框架以任何顺序显示窗口,因为该顺序是未定义的。

首先,确保在 Interface Builder 中为您的窗口选中启动时可见复选框。如果是这样,您将无法有效地控制窗口显示。默认情况下它是打开的。

接下来,为要加载的每个窗口笔尖使用 NSWindowController 子类。然后,在主应用程序控制器中,您可以控制何时实例化这些 NSWindowController 对象以及何时调用它们的 -showWindow 方法。

在您的示例中,您可能会在应用程序委托的 -applicationDidFinishLaunching: 方法中实例化 MainWindow.xibNSWindowController

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文