【问题标题】:Getting Notifications of isDocumentEdited获取 isDocumentEdited 的通知
【发布时间】:2010-08-07 03:31:02
【问题描述】:

是否可以在不调用 will/didChangeValueForKey: 方法的情况下绑定/获取 NSDocument 的 isDocumentEdited 属性的通知?

【问题讨论】:

    标签: objective-c cocoa nsdocument nsundomanager


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我会扩展Mike Abdullah's answer:

      为了让绑定与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"];
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-05
        • 2021-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多