开发者

Programmatically save causes document to think other app changes doc when re-opening file

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:

saveDocumen开发者_StackOverflow中文版tWithDelegate: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: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.

All help is appreciated. Thanks


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]

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.


To get it to work as you want, you can probably fix it by using the saveToURL:... method and then call -[NSWindow setDocumentEdited:] or -[NSDocument updateChangeCount:] which will stop the menu item from being disabled.

However, I'm not sure your overall approach is right. If you have a save menu item, I don't think you should be saving automatically unless you're using Lion’s auto-save feature (recommended) in which case you would call different methods.

And even if you did decide to stick with the auto-saving as you have it now, why wouldn’t you want the menu item to be disabled? It’s disabled because there are no changes to save.

Why are you auto-saving the file anyway?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜