调用updateChangeCount时,UIDocument自动保存不起作用 [英] UIDocument autosave not working when calling updateChangeCount

查看:151
本文介绍了调用updateChangeCount时,UIDocument自动保存不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIDocument的自定义子类,用于存储我的应用程序的用户内容.我直接调用-[UIDocument updateChangeCount:UIDocumentChangeDone]来跟踪对文档的更改.保存和加载工作正常,但是文档永远不会自动保存.为什么会这样?

I have a custom subclass of UIDocument that I use to store the user's content for my app. I call -[UIDocument updateChangeCount:UIDocumentChangeDone] directly to track changes to the document. Saving and loading work fine, but the document never autosaves. Why would this be happening?

推荐答案

事实证明,问题是我没有从主线程中调用-[UIDocument updateChangeCount:].尽管UIDocument不是UI元素,但它仍然是UIKit的一部分,因此关于始终与主线程中的UIKit类进行交互的通常警告仍然适用.

It turns out that the problem was that I wasn't calling -[UIDocument updateChangeCount:] from the main thread. Despite the fact that UIDocument isn't a UI element, it is still part of UIKit and so the usual caveats about always interacting with UIKit classes from the main thread still applies.

将代码包装到主队列中可以解决此问题:

Wrapping the code in a dispatch to the main queue fixed the issue:

dispatch_async(dispatch_get_main_queue(), ^{
    [doc updateChangeCount:UIDocumentChangeDone];
});

这篇关于调用updateChangeCount时,UIDocument自动保存不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆