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.
Open
ToDoDocument.m.Import
InfoWindowController.h. While you’re here, importSelectionNotifyMatrix.has well, to pick up theRowSelectedNotificationdeclaration.Add the following code to the
controlTextDidEndEditing:method:/* ... */ [self updateChangeCount:NSChangeDone]; [[NSNotificationCenter defaultCenter] postNotificationName: ToDoItemChangedNotification object:selectedItem userInfo:nil];Open
InfoWindowController.mand modify thewindowDidLoadmethod to register the InfoWindowController as an observer of theToDoItemChangedNotification:[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectedItemChanged:) name:ToDoItemChangedNotification object:nil];Add the definition of the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access