【问题标题】:UIDocument loadFromContents: is not always called after document was changed on another deviceUIDocument loadFromContents:在另一台设备上更改文档后并不总是调用
【发布时间】:2014-03-16 16:56:53
【问题描述】:

我有一个自定义 UIDocument 子类并实现了 loadFromContents:contentsForType:

为了检测文档在另一台设备上被更改,我按照Apple documentation 中的建议向loadFromContents: 添加了一个委托:

- (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError **)outError {
    // load from disk […]

    if ([_delegate respondsToSelector:@selector(noteDocumentContentsUpdated:)]) {
        [_delegate noteDocumentContentsUpdated:self];
    }
    return YES;
}

我的问题是,当我在另一台设备上更改文档时,我收到文档状态更改通知(edit_disabled 后跟normal),但内容重新加载并loadFromContents:没有被调用。

内容肯定是在磁盘上更新的。当我通过 UI 手动重新打开文档时,我会立即看到最新的更改。

其他时候它可以工作并且自动调用loadFromContents:。我不知道为什么它有时不起作用。有没有其他人看到过这个问题?

【问题讨论】:

    标签: ios objective-c icloud uidocument


    【解决方案1】:

    您可能希望在通知后手动执行文档版本解析和/或在文档再次变为正常状态后重新加载文档。

    查看以下UIDocument 方法来简单地重新加载文档的内容:

    - (void)revertToContentsOfURL:(NSURL *)url completionHandler:(void (^)(BOOL success))completionHandler;
    

    【讨论】:

      猜你喜欢
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多