Page 1 of 1

Register for Notifications

PostPosted: Thu Apr 08, 2010 8:12 pm
by udo.killermann
Hello OB-Forum,

I am experimenting with NSComboBox right now. Looking at the class reference I see notifications for the combobox which are sent when certain conditions change (e.g. NSComboBoxSelectionDidChangeNotification). How can I register to receive notifications in my OB Code? I tried to capture it using Event keyword but did not suceed. Did I miss something?

Thanks for your answer

Re: Register for Notifications

PostPosted: Fri Apr 09, 2010 9:43 am
by berndnoetscher
Well, I assume you just want to react to the user changes of the selected item in the NSComboBox. This is how it works.

You need to declare an IBAction in code.

Code: Select all
IBAction cbselected(sender As id)
  Alert(myCombobox.SelectedObject())  ' myCombobox is set as IBOutlet somewhere in code here
End IBAction

And then go to Interface Builder and connect the NSComboBox to the IBAction.

Whenever you change the selected item an alert will appear showing the selected item as text.

By the way, the keyword Event is used to override existing class implementations.

Re: Register for Notifications

PostPosted: Fri Apr 09, 2010 6:56 pm
by udo.killermann
Thanks for your answer. It took me a while to understand the concept of wiring UI elements within IB to actions and outlets. Why the name of the notification isn't even referenced within IB was counterintuitiv to me.

Thanks for hinting me to the event concept to override class methods.

BTW: I started coding in Basic on an Apple ][+ in the late 70s. I am happy to see that a modern implementation is back on my Apple (this time MacBook).