8.6. Tracking Changes with Notifications

One of the common problems you may find yourself addressing over and over again in Cocoa programs, and in graphic user interface programs in general, is knowing when to redraw your application's interface. In the Model/View/Controller design pattern, the controller object is responsible for updating the model and then redrawing the appropriate views. You have seen how Cocoa Bindings uses Key Value Observing to implement this approach. When manually connecting your interface's outlets and actions, you'll need to look for other solutions to this problem.

The notion of just forcing this responsibility onto the controller makes sense, but it breaks down when you have several controllers: when one controller modifies the model data, the second controller needs to know the model has changed, so it can update itself accordingly. Consider the case of Slide Master's slide show document. The SlideShowWindowController defines the logic (or will define the logic) governing the slide show's user interface, including an image view and a table of slides. The SlideShowDocument provides storage for your model (a list of slides) as well as some common controller functionality, such as tracking open windows and handling events. If you change the slide show's data using a menu command, something needs to tell the SlideShowWindowController the slide data has changed.

Several traditional solutions to this problem exist, not including using Cocoa Bindings and ...

Get Beginning Mac OS® X Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.