Cocoa saveToURL不工作?

时间:2013-07-29 21:45:46

标签: cocoa nsdocument

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

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

//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存在并包含进行这些调用时的更新数据。

我错过了什么?

非常感谢所有人提供任何信息!

1 个答案:

答案 0 :(得分:0)

我想我找到了它。 fileURL错了。