Search code examples
objective-ccocoakey-value-observingnsoutlineviewnstreecontroller

Automatically update NSOutlineView upon model changes without NSTreeController


If I changed my NSOutlineView from using bindings and an NSTreeController to having a data source and a delegate, how would I automatically update the NSOutlineView, if my model tree changes? Should I observe the childNodes property of every single node in my tree with my controller and trigger a reload when a change occurs? Or is there another way?


Solution

  • That's one way. Another way would be for the model to post notifications when it changes and have your controller observe those.

    Also, a model doesn't typically change spontaneously. Usually, the change is initiated outside of the model in response to some event. A controller is usually doing that. So, that controller could also provoke an update to the outline view. (There may be multiple controllers, so maybe the controller that initiates the model change just informs a window or view controller, which would be responsible for updating the outline view.)