Why 2 updateChangeCount


#1

why are there 2 update change count in the code of TahDoodle.
One in addTasks method and one in the method of protocol. Here is the code

[code]-(void)addTasks:(id)sender{
//If there is no array yet, create one
if (!self.tasks){
self.tasks = [NSMutableArray array];
}

[self.tasks addObject:@"New Item"];

// - reloadData tells the table view to refresh and ask its dataSource
// (which happens to be this BNRDocument object in this case)
// For new data to display
[self.taskTable reloadData];

//-updateChangeCount : tells the application whether or not the document
//has unsaved changes, NSChangeDone flags the document as unsaved
[self updateChangeCount:NSChangeDone];

}
[/code]

and protocol’s method code

[code]-(void)tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
//when the user changes a task on the table view, update the tasks array
[self.tasks replaceObjectAtIndex:row withObject:object];
//And then flag the document as having unsaved changes.
[self updateChangeCount:NSChangeDone];

}[/code]


#2

In Mac development, when you’re writing a Document-based application (like this one), you can update your application state to notify the user that the document has changed since the last time it was saved. Think about a word processor like Pages or Microsoft Word. Do you ever notice that at the top of the application window, sometimes the file’s icon is grayed out and sometimes it’s not? When the file’s icon is gray, this tells the user that they need to save their work.

As a developer, when you detect that something has changed (in this case, if the user adds a new task), you can tell the application to show the user that there is now unsaved work by using NSDocument’s updateChangeCount: method.


#3

MikeyWard,

But that does not explain why there are two methods for updateChangeCount.

Anyways, I believe the protocol method is for changing the object that is already in an array whereas the one where we declared under “Actions” is for when we are adding a completely new task.

Two different methods which both at the end will do the updateChangeCount.