NSPopover上的控件没有响应

时间:2015-10-03 22:51:05

标签: xcode macos nspopover nscontrol

设置如下:

  • 具有一个视图控制器的菜单应用程序。视图控制器中的视图存储在NSMenuItem
  • 该视图控制器有一个按钮,我们将调用“设置”按钮'
  • 单击“设置”按钮时,将打开NSPopover。
  • NSPopover将其内容设置为SettingsViewController
  • SettingsViewController有一个按钮。

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
    }
}

Swift Problem

0 个答案:

没有答案