O'Reilly logo

Learning Cocoa by Apple Computer Inc

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

Data Synchronization

Now it’s time to add functionality to the ToDoDocument class to facilitate synchronizing data display with an Info window. The Info window must display information about the ToDoItem currently selected in the ToDoDocument and update its view if a new document is opened (or brought to the front). Also, the ToDoDocument must update its display when an item is modified in the Info window. In this section you’ll make this communication work.

The controlTextDidEndEditing: method in ToDoDocument.m is where ToDoItems are added, removed, or modified, so you must let the Info window know when there’s a change in the current ToDoItem. Modify the method to post a ToDoItemChangedNotification, passing in selectedItem as the object related to the notification.

  1. Open ToDoDocument.m.

  2. Import InfoWindowController.h. While you’re here, import SelectionNotifyMatrix.h as well, to pick up the RowSelectedNotification declaration.

  3. Add the following code to the controlTextDidEndEditing: method:

        /* ... */
        [self updateChangeCount:NSChangeDone];
    
        [[NSNotificationCenter defaultCenter] postNotificationName:
                ToDoItemChangedNotification object:selectedItem
                userInfo:nil];
  4. Open InfoWindowController.m and modify the windowDidLoad method to register the InfoWindowController as an observer of the ToDoItemChangedNotification:

    [[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(selectedItemChanged:)
            name:ToDoItemChangedNotification object:nil];
  5. Add the definition of the ...

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