Show NSWindowController from StatusMenu

问题内容:

I have an app working from an extension in the Status Menu.

I have there a button “Settings” on which when the user taps should launch a particular view of my storyboard.

I have tried many different ways, Open NSWindowController from NSMenu, Cocoa – How to bring particular window to come in foreground from StatusMenu.

Here is my current code :

StatusMenu.swift

func showSettings() {

  var mainWindowController = MainWindowController()
  mainWindowController.showWindow(nil)

}

MainWindowController.swift

class MainWindowController: NSWindowController {

 override func windowDidLoad() {
   super.windowDidLoad()

   self.window?.center()
   self.window?.makeKeyAndOrderFront(nil)
   NSApp.activate(ignoringOtherApps: true)

   }

}

问题评论:

    
move mainWindowController declaration out of your showSettings method

原文地址:

https://stackoverflow.com/questions/47755471/show-nswindowcontroller-from-statusmenu

添加评论

友情链接:蝴蝶教程