OS X storyboard: how to show a window programmatically?

后端 未结 2 1069
一向
一向 2021-01-05 19:36

I am creating an OS X status bar application.

I am trying to achieve the following:

  • app starts invisible, with menu bar item
  • click on menu bar
2条回答
  •  梦毁少年i
    2021-01-05 20:34

    The makeKeyAndOrderFront method is a NSWindow method, but instantiateInitialController returns the window controller, not its window.

    Also, if the window is hidden on deactivate, you wouldn't want to instantiate another copy. Keep a reference to the window and re-show that.

    Finally, you may need to bring the app to the front too. Call [NSApp activateIgnoringOtherApps:YES] (or the Swift equivalent).

提交回复
热议问题