0

我有一个可以使用 File->Save 命令成功保存的 NSDocument 子类。

当我的应用程序运行特定操作时,它会更新此文件,并且需要自动将更新后的文件保存到磁盘。我已经尝试了以下所有方法:

//Attempt #1. No error but document in not saved to disk.
NSError * theError;
[myDocument invalidateRestorableState]; //mark document as dirty
[myDocument writeSafelyToURL:[myDocument fileURL] ofType:CONSTANT_CONTAINING_FILE_EXTENSION forSaveOperation:NSAutosaveInPlaceOperation error:&theError];
if (theError != nil)
    [NSApp presentError:theError];

//Attempt #2. Completion handler is not called. Doc is not saved to disk.
[myDocument saveToURL:[myDocument fileURL] ofType:CONSTANT_CONTAINING_FILE_EXTENSION forSaveOperation:NSAutosaveInPlaceOperation completionHandler:^(NSError *errorOrNil) {
 if (errorOrNil != nil)
        [NSApp presentError:errorOrNil];
}];

//Attempt #3. No error but doc is not saved to disk.
NSError * theError;
[myDocument saveToURL:[myDocument fileURL] ofType:CONSTANT_CONTAINING_FILE_EXTENSION forSaveOperation:NSSaveOperation error:&theError];
if (theError != nil)
    [NSApp presentError:theError];

//Attempt #4. didSaveDocument is not called. Doc is not saved to disk.
[myDocument saveDocumentWithDelegate:myDocument didSaveSelector:@selector(didSaveDocument:didSave:contextInfo:) contextInfo:nil];

myDocument 存在并包含进行这些调用时的更新数据。

我错过了什么?

非常感谢大家提供任何信息!

4

1 回答 1

0

我想我找到了。文件 URL 错误。

于 2013-07-29T21:50:46.193 回答