以编程方式保存原因文档,以便在重新打开文件时考虑其他应用程序更改文档 [英] Programmatically save causes document to think other app changes doc when re-opening file

查看:144
本文介绍了以编程方式保存原因文档,以便在重新打开文件时考虑其他应用程序更改文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪,我非常感谢所有的帮助=)

This is pretty weird and I would very much appreciate all help =)

我有一个基于文档的应用程序,应该可以对文档执行一些操作文件。为此,我每次调用文档操作时保存文档。为此,我使用的方法:

I have a document based app where it should be possible to perform some actions on the document file. To do so I'm saving the document every time the document actions are called. To do so I'm using the method:


saveDocumentWithDelegate:didSaveSelector:contextInfo:

saveDocumentWithDelegate:didSaveSelector:contextInfo:

问题是,当关闭文档,从最近的文件菜单中重新打开它,然后再执行操作,我将显示对话框,说

The problem is, that when closing the document, reopening it from the recent files menu and then performing the action again I'm being presented with the dialog box saying that


此文件的文件自您打开或保存后已由另一个应用程序更改。

This document’s file has been changed by another application since you opened or saved it.

但是使用保存菜单项时不是这样。

However this is not the case when using the save menu item.

我尝试了不同的保存方法:

I've tried with different save methods:


saveToURL:ofType:forSaveOperation:错误:

saveToURL:ofType:forSaveOperation:error:

导致我所寻找的行为有一个副作用:执行操作后保存菜单项被停用。

And even though this results in the behavior I'm looking for there is a side effect: The save menu item becomes deactivated after performing the action.

所以我的问题是:我应该如何正确以编程方式执行保存操作?我看过文档,但我没有看到任何看起来像一个明显的解决方案。

So my question is: How should I correctly perform save operations programmatically? I've looked through the docs but I haven't seen anything which looks like an obvious solution.

感谢所有帮助。感谢

推荐答案

我找到了这个问题的解决方案。 code> 的方法覆盖 configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error: 方法NSPersistentDocument 。问题解决时,我删除字符串

I found solution for this problem in my case. Problem was in options in overriding of configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error: method of NSPersistentDocument. Problem was solved when I delete string

[options setObject:[NSNumber numberWithBool:YES] forKey:NSSQLiteManualVacuumOption]

我出于某种原因使用了vacuum选项。不知道怎么,但它造成保存问题。当我拒绝此选项时,问题已消失。

I used vacuum option for some reason. Don't know how but it caused problem with saving. When I refused this option the problem has disappeared.

这篇关于以编程方式保存原因文档,以便在重新打开文件时考虑其他应用程序更改文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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