开发者

Getting Notifications of isDocumentEdited

开发者 https://www.devze.com 2023-01-11 01:32 出处:网络
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:

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"];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号