开发者

Check whether save successfully happened in Cocoa Document Based application

开发者 https://www.devze.com 2023-03-01 12:29 出处:网络
I have a Cocoa document based picture editing application. As usual, my application has both File -> Save menu and File -> Save As menu.

I have a Cocoa document based picture editing application. As usual, my application has both File -> Save menu and File -> Save As menu.

File -> Save menu is linked to saveDocument: in NSDocument subclass

File -> Save As menu is linked to saveDocumentAs: in NSDocument subclass

In both ca开发者_如何学JAVAses, on a successful save, I want to present a NSAlert sheet to user saying that the save was successful and this sheet also presents the user with an option to upload the document to Facebook etc.

How do I know, that the document got saved succesfully?

I understand that in case of File -> Save As I can create a new action method mySaveDocument: and invoke

saveDocumentWithDelegate:didSaveSelector:contextInfo:

from mySaveDocument: but what should I do for File -> Save As ?


In your NSDocument subclass, override:

- (BOOL)saveToURL:(NSURL *)absoluteURL
           ofType:(NSString *)typeName
 forSaveOperation:(NSSaveOperationType)saveOperation
            error:(NSError **)outError
{
    BOOL success = [super saveToURL:absoluteURL
                             ofType:typeName
                   forSaveOperation:saveOperation
                              error:outError];

    if (success) {
        …
    }

    return success;
}

This method is called whenever a document is saved.

For more information on what happens when a document is saved, read the Message Flow in the Document Architecture page of the Document-Based Applications Overview document.

0

精彩评论

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