Bla*_*ard 2 macos cocoa nsmenuitem segue
我想在用户点击Preferences...菜单或键入⌘+ 时在我的Cocoa应用程序中打开首选项窗格,.所以我从首选项菜单项连接到故事板中的窗口控制器作为showsegue.
但是,虽然这会在用户点击时打开首选项窗格Preferences...,但如果用户在关闭窗格之前再次点击菜单项,则另一个窗格将启动并显示在屏幕上.
我想在屏幕上只有一个偏好设置面板,但我该怎么办呢?我想只在故事板上进行设置,避免编码使得无聊菜单项的嵌套...
为了防止窗口多次启动,您可以Single从Storyboard上的Window Controller的Attribute Inspector中进行选择.
默认值为Multiple,导致无限窗口启动.
或者,如果你想使用代码,我将在这里做些什么AppDelegate.swift.
extension AppDelegate: NSSeguePerforming {
func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
if identifier == OpenPreferencesIdentifier {
let windows = NSApp.windows
for window in windows {
if window.windowController?.className == MyPreferencesWindowController.className() {
return false
}
}
}
return true
}
}
Run Code Online (Sandbox Code Playgroud)
另外,不要忘记在Storyboard上设置适当的segue标识符.