Restoring from versions browser on OSX lion not wo

2019-03-04 22:31发布

I'm trying to restore a document based application from a previous version on Lion. When I select "restore version", the text view doesn't reflect the changes. However, if I close the application and reopen, the changes are there.

I'm using the file wrapper variants of NSDocument, so how can I make the text view's text storage reflect the version that's selected immediately? Am I missing something?

1条回答
Evening l夕情丶
2楼-- · 2019-03-04 23:24

I had a similar problem recently (my interface didn't seem to update). Are you updating your interface in windowControllerDidLoadNib: or awakeFromNib ? When a document is reverted (revert to last saved, or selecting a version in the versions browser), windowControllerDidLoadNib: is not called again because the document is already loaded, but your file wrapper method will be.

I'm not sure if this is the best solution, but what I do is update the UI in the read wrapper method only if the document is being reverted. I do this by checking if an outlet (like your textview) is not nil.

Update:

A better solution is overriding -revertToContentsOfURL:ofType:error:

- (BOOL)revertToContentsOfURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError * __autoreleasing *)outError
{
    BOOL reverted = [super revertToContentsOfURL:absoluteURL ofType:typeName error:outError];
    if (reverted)
    {
        // re-update interface
    }
    return reverted;
}
查看更多
登录 后发表回答