I have a toolbar in my Mac app that uses storyboards. I added a button to the toolbar. I connected the toolbar item for the button to the window controller's First Responder, with the action being an IBAction I wrote.
In Interface Builder's Connections Inspector, I can see the toolbar item has a sent action to First Responder. The button itself has no sent actions.
Here's the code for my IBAction.
@IBAction func addTagFromToolbar(_ sender: NSToolbarItem) {
let tagTitle = sender.label
createTag(name: tagTitle)
NotificationCenter.default.post(name: NSText.didChangeNotification, object: textView)
}When I click the button, an exception is thrown on Line 2, with the following error message appearing the debug console:
[NSButton label]: unrecognized selector sent to instance 0x600003508580
Even though I set the type of sender to NSToolbarItem and made sure the toolbar item (and not the button) is connected to First Responder, the app is using the button as the sender.
What do I have to do to make the IBAction's sender the toolbar item instead of the button?