1

I have a toolbar on my macOS app, developed in Swift. The toolbarItem is dragable onto the NSWindowController, and I can setup an IABAction function, I just have a print in the function at the moment. And when I click on the button nothing happen the click does not seem to be recognised as an action ?

I had a few more line of code in the function but deleted it and now have just the print("test") line.

@IBAction func exportCsvClicked(_ sender: NSToolbarItem) {   
print("test") }

No output observed, so I'd love to get "test" in the console when I click on this button.

Here is a list of the connections associated with the toolbarItem.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Remi
  • 11
  • 2

1 Answers1

0

I found a way to get around the fact that the IBAction from an NSToolbarItem does not recognise the click on this item:

1/I made a customSegue from the item to the main window controller (it can go anywhere)

2/The prepare for segue function posts a notification to the notification saying that the item has been clicked.

3/The main view controller observes the notification and presents, either has a popup or a sheet (I got two buttons), the view that I have setup in the storyboard (referencing with the storyboardID). I found that you need to pass on all the necessary variable to setup the view from the main view Controller, and that there was issue of code in the viewDidLoad function of the sheet/popup view not running, I am suspecting that they might be different instances.

Remi
  • 11
  • 2