0

I have an application macOS with 2 buttons but they are not trigger I have connected up IBActions to buttons

Document

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

and MainWindowController

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

}

I have all tried I do not know what to do

I have certainly forgotten something in another application NSPersistentDocument there is no problem

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

enter image description here

thierryH
  • 37
  • 1
  • 6
  • Is the dropbox project related to the question? – Willeke Jan 18 '18 at 14:48
  • yes this is the project it's a big project at the start I raised everything that was useless – thierryH Jan 18 '18 at 15:07
  • The code in the question is not present in the project. The buttons in the project are connected to the tree controller. It's the same project as a previous question about [NSOutlineView with NSTreeController bindings with core data](https://stackoverflow.com/questions/48111823/nsoutlineview-with-nstreecontroller-bindings-with-core-data). – Willeke Jan 18 '18 at 16:04
  • sorry it's corrected now – thierryH Jan 18 '18 at 16:16
  • The view controller `mainWindowController` is released at the end of `windowControllerDidLoadNib`. – Willeke Jan 18 '18 at 17:14
  • I modified and it works I will put the solution for others thank you very much – thierryH Jan 18 '18 at 20:01

0 Answers0