在NSPersistentDocument for macOS中不会触发ibaction

时间:2018-01-18 14:15:59

标签: cocoa ibaction nspersistentdocument

我有一个带有2个按钮的应用程序 macOS ,但它们不是触发器 我已将IBActions连接到按钮

文档

override func windowControllerDidLoadNib(_ windowController: NSWindowController) {
    super.windowControllerDidLoadNib(windowController)
    // user interface preparation code
    guard let context = self.managedObjectContext else { fatalError("context is nil") }
    mainObjectContext = context

    let mainWindowController = MainWindowController(nibName: NSNib.Name(rawValue: "MainWindowController"), bundle: nil)
    customView1.addSubview(mainWindowController.view)
    setUpLayoutConstraints(item: mainWindowController.view, toItem: customView1)

}

func setUpLayoutConstraints(item : NSView, toItem: NSView)
{
    item.translatesAutoresizingMaskIntoConstraints = false
    let sourceListLayoutConstraints = [
        NSLayoutConstraint(item: item, attribute: .left, relatedBy: .equal, toItem: toItem, attribute: .left, multiplier: 1, constant: 0),
        NSLayoutConstraint(item: item, attribute: .right, relatedBy: .equal, toItem: toItem, attribute: .right, multiplier: 1, constant: 0),
        NSLayoutConstraint(item: item, attribute: .top, relatedBy: .equal, toItem: toItem, attribute: .top, multiplier: 1, constant: 0),
        NSLayoutConstraint(item: item, attribute: .bottom, relatedBy: .equal, toItem: toItem, attribute: .bottom, multiplier: 1, constant: 0)]
    NSLayoutConstraint.activate(sourceListLayoutConstraints)
}

和MainWindowController

类MainWindowController:NSViewController {

@objc var managedObjectContext: NSManagedObjectContext = mainObjectContext
@objc dynamic var customSortDescriptors = [NSSortDescriptor(key: "name", ascending: true, selector: #selector(NSString.localizedStandardCompare(_:)))];

@IBOutlet weak var textFiled: NSTextField!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do view setup here.
    print("hello")
    textFiled.stringValue = "hello"
}

@IBAction func actionAddNew(_ sender: Any) {
    print("add")
    textFiled.stringValue = "add"
}

@IBAction func actionRemove(_ sender: Any) {
    print("remove")
    textFiled.stringValue = "remove"
}

}

我已经尝试过,我不知道该怎么做

我当然忘记了什么 在另一个应用程序NSPersistentDocument中没有问题

https://www.dropbox.com/s/qlww3hgii7wamup/CoreDataDragDropSwift2.zip?dl=0

enter image description here

0 个答案:

没有答案