ibaction не запускается в NSPersistentDocument для macOS

У меня есть приложение 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

введите здесь описание изображения


person thierryH    schedule 18.01.2018    source источник
comment
Связан ли проект dropbox с вопросом?   -  person Willeke    schedule 18.01.2018
comment
да это проект это большой проект в начале я поднял все что было бесполезно   -  person thierryH    schedule 18.01.2018
comment
Код в вопросе отсутствует в проекте. Кнопки в проекте подключены к контроллеру дерева. Это тот же проект, что и предыдущий вопрос о NSOutlineView с привязками NSTreeController к основным данным.   -  person Willeke    schedule 18.01.2018
comment
извините сейчас исправлено   -  person thierryH    schedule 18.01.2018
comment
Контроллер представления mainWindowController освобождается в конце windowControllerDidLoadNib.   -  person Willeke    schedule 18.01.2018
comment
Я модифицировал, и это работает, я поставлю решение для других, большое спасибо   -  person thierryH    schedule 18.01.2018