Search code examples
objective-ccocoansnotificationsnstabview

Cocoa - finding out when an NSTabView has changed its tabs


How can I find out when a NSTabViewItem has been changed, i.e. a user has changed the view of an NSTabView?

Ideally I want to generate a notification but any solution would be welcome.


Solution

  • My original answer suggested to observe selectedTabViewItem of NSTabView, but that doesn't seem to work (on testing I can only get it to observe NSKeyValueObservingOptionInitial).

    A probably smarter solution is to use a delegate. Implement tabView:didSelectTabViewItem: in the relevant controller.

    Docs here.