How do I use Action Invocation in Xcode Interface Builder

834 Views Asked by At

I am having trouble getting the IB Action Invocation to work when using the Argument bindings. Can someone explain how this is meant to work. If I don't use the Argument binding then the binding works but the method is called with a nil parameter. I assume that the Argument binding is intended to set the parameter that will be passed in the method invocation. In my case I want to get a reference to the Table Cell Views object. I get a compiler error as follows:

Exception while running ibtool: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil

I am binding the action invocation to a Button in the Table Cell View.

enter image description here

1

There are 1 best solutions below

1
Willeke On BEST ANSWER

Workaround:

In the Report Queue Table View Controller class:

  • Add protocol NSTableViewDelegate to the declaration. You don't have to implement any methods.
  • Add outlets for the array controller and the table view.
  • Add an action method
@IBAction func cancelAction(_ sender: NSButton) {
    let row = tableView.row(for: sender)
    if let objects = arrayController.arrangedObjects as? [String] {
        let object = objects[row]
        cancel(object)
    }
}

In IB:

  • Connect the outlets.
  • Connect the delegate of the table view to the Report Queue Table View Controller.
  • Connect the action of the button to cancelAction of the Report Queue Table View Controller.
  • Remove the button action bindings.