设置如下:
SettingsViewController中的按钮在单击时不会设置动画。它不响应任何用户操作。我不是说'行动'被解雇了,我的意思是没有身体反应。就好像按钮被禁用了,即使我没有禁用它。
AppDelegate.swift:
class AppDelegate: NSObject, NSApplicationDelegate {
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(NSSquareStatusItemLength)
let direktMain = DirektMainViewController(nibName:"DirektMainViewController", bundle:nil)
let mainItem = NSMenuItem()
func applicationDidFinishLaunching(aNotification: NSNotification) {
// Insert code here to initialize your application
statusItem.button!.title = "Dkt"
statusItem.menu = NSMenu()
mainItem.view = direktMain!.view;
statusItem.menu!.addItem(mainItem)
}
}
SettingsViewController.swift:
class SettingsViewController: NSViewController {
@IBOutlet weak var quittButton: NSButton?
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
print("SettingsViewController. ViewDidLoad")
}
@IBAction func quitAction(sender: AnyObject) {
print("Time to quit!")
}
}
DirektMainViewController.swift:
class DirektMainViewController: NSViewController {
@IBOutlet weak var settingsButton: NSButton?
let popoverSettings = NSPopover()
let settingsViewController = SettingsViewController(nibName:"SettingsViewController", bundle:nil)
@IBAction func settingsButtonAct(sender: AnyObject) {
print("Hey: ", __FUNCTION__)
if !popoverSettings.shown {
popoverSettings.showRelativeToRect(settingsButton!.bounds, ofView: settingsButton!, preferredEdge: NSRectEdge.MinY)
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
print("DirektMainViewController viewDidLoad")
popoverSettings.contentViewController = settingsViewController
}
}