【发布时间】:2017-12-11 14:50:39
【问题描述】:
我有一个通过状态菜单中的扩展程序运行的应用程序。
我有一个“设置”按钮,当用户点击它时应该启动我的故事板的特定视图。
我尝试了很多不同的方法,Open NSWindowController from NSMenu、Cocoa - How to bring particular window to come in foreground from StatusMenu。
这是我当前的代码:
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)
}
}
【问题讨论】:
-
将 mainWindowController 声明移出 showSettings 方法
-
@LeoDabus 只有第一行?它不起作用...
-
你确定 window 属性不是 nil 吗?
-
@LeoDabus 是的...是因为我在故事板中调用了特定的 NSWindowController 吗?我看到其他一些需要 windowNibName 函数的解决方案
标签: ios swift macos cocoa nswindowcontroller