Getting Notifications of isDocumentEdited
is it possible to bind/get notifications of the isDocumentEdited property of NSDocument witho开发者_C百科ut calling the will/didChangeValueForKey: methods on every change?
Override -updateChangeCount:
in your subclass so it posts an NSNotification
or does whatever work you're after.
I'll extend Mike Abdullah's answer:
To get bindings to work with isDocumentEdited
, I implemented the following override on the NSDocument
method:
- (void)updateChangeCount:(NSDocumentChangeType)change
{
[self willChangeValueForKey:@"isDocumentEdited"];
[super updateChangeCount:change];
[self didChangeValueForKey:@"isDocumentEdited"];
}
- (void)updateChangeCountWithToken:(id)changeCountToken forSaveOperation:(NSSaveOperationType)saveOperation
{
[self willChangeValueForKey:@"isDocumentEdited"];
[super updateChangeCountWithToken:changeCountToken forSaveOperation:saveOperation];
[self didChangeValueForKey:@"isDocumentEdited"];
}
精彩评论