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.h
as well, to pick up theRowSelectedNotification
declaration.Add the following code to the
controlTextDidEndEditing:
method:/* ... */ [self updateChangeCount:NSChangeDone]; [[NSNotificationCenter defaultCenter] postNotificationName: ToDoItemChangedNotification object:selectedItem userInfo:nil];
Open
InfoWindowController.m
and modify thewindowDidLoad
method 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 ...
Get Learning Cocoa 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.