获取 isDocumentEdited 的通知

发布于 2024-09-12 22:19:48 字数 95 浏览 3 评论 0原文

是否可以绑定/获取 NSDocument 的 isDocumentEdited 属性的通知,而无需在每次更改时调用 will/didChangeValueForKey: 方法?

is it possible to bind/get notifications of the isDocumentEdited property of NSDocument without calling the will/didChangeValueForKey: methods on every change?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江南烟雨〆相思醉 2024-09-19 22:19:48

在您的子类中覆盖 -updateChangeCount: ,以便它发布 NSNotification 或执行您想要执行的任何操作。

Override -updateChangeCount: in your subclass so it posts an NSNotification or does whatever work you're after.

安静 2024-09-19 22:19:48

我将扩展 Mike Abdullah 的答案

为了让绑定与 isDocumentEdited 一起使用,我实现了以下重写 NSDocument 方法:

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

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"];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文