O'Reilly logo

Beginning Mac OS® X Programming by Drew McCormack, Michael Trent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required