如何在启动时在 Cocoa 应用程序中打开一个新窗口
我创建了一个可可应用程序(不是基于文档的)并具有默认的 MyAppDelegate 类和 MainMenu nib 文件。我还创建了一个新的笔尖,其中包含一个名为 Splash 的窗口和一个名为 SplashWindowController 的窗口控制器类 (NSWindowController)。
我想要的是,当应用程序启动而不是打开 MainMenu 笔尖窗口时,我想打开启动窗口。
我认为我必须在 AppDelegate 类中创建 SplashWindowController 的实例,然后实例化该窗口并将其设置为前面。不过,我尝试了一些方法,例如在我的 AppDelegate 类中包含对 SplashWindowController.h 文件的引用,并向我的 MainMenu 笔尖添加一个对象并将其类设置为 SplashWindowController。但两者都没有运气。
如果有人可以帮助我完成这个任务,我将非常感激,因为我一天中大部分时间都在做这个(看起来像是一项简单的任务)。
提前致谢。
I have created a cocoa application (not document based) and have the default MyAppDelegate class and the MainMenu nib file. I have also created a new nib which contains a window called Splash and a window controller class (NSWindowController) called SplashWindowController.
What I would like is that when the application starts instead of the MainMenu nib window opening I would like to open the Splash window.
I think that I have to create an instance of my SplashWindowController in my AppDelegate class and then instantiate the window and set it to front. However I have tried several things like including a reference to the SplashWindowController.h file in my AppDelegate class and also adding an object to my MainMenu nib and setting its class to be SplashWindowController. But have had no luck with either.
If anybody out there could help me with this one it would be much appreciated as have been at this (what seems like a simple task) for the best part of a day.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地将两个窗口合并到一个 .xib 文件中。
ExampleAppDelegate.h
ExampleAppDelegate.m
MainMenu.xib
结果
启动时仅可见启动窗口。启动窗口将在 10 秒后自动关闭。用户可以通过按下按钮直接关闭启动窗口。关闭启动窗口后将显示主窗口。
You can simply combine both windows into one .xib file.
ExampleAppDelegate.h
ExampleAppDelegate.m
MainMenu.xib
Result
At launch only the splash window is visible. The splash window automatically closes after 10 seconds. The user can close the splash window directly by pressing the button. The main windows shows up after closing the splash window.