0

每当我的文档被重命名时,自动保存就会被阻止,并且重命名后的第一次保存会显示如图所示的消息。

在此处输入图像描述

从技术上讲,这不是问题,因为任何一个按钮都会将用户带回可自动保存的状态,但这会让我的用户感到困惑。

我试过钩住这个方法

-(void)moveToURL:(NSURL *)url completionHandler:(void (^)(NSError *))completionHandler
{
    void(^takeoverblock)(NSError *error) = ^(NSError *error){

        if (completionHandler) {
            completionHandler(error);
        }

        if (!error) {

            [self updateChangeCountWithToken:[self changeCountTokenForSaveOperation:NSAutosaveInPlaceOperation] forSaveOperation:NSAutosaveInPlaceOperation];
        }

    };

    [super moveToURL:url completionHandler:takeoverblock];
}

并使用各种风格的updateChangeCount:andupdateChangeCountWithToken: 但警告始终出现。

如何将文档置于重命名/移动后恢复标准自动保存行为的状态。?

4

1 回答 1

3

友好的 Apple 工程师给出的答案是,当底层 sqlite 文件上的 modifyDate与实例fileModificationDate上的属性不同时,就会出现这种NSPersistentDocument情况,以便fileModificationDate在移动后解决重置

moveToUrl:像这样覆盖

-(NSDate *)modDateForURL:(NSURL *)url
{
    NSDictionary *dict = [[NSFileManager defaultManager] attributesOfItemAtPath:[url path] error:NULL];
    return dict[NSFileModificationDate];
}


-(void)moveToURL:(NSURL *)url completionHandler:(void (^)(NSError *))completionHandler
{

    void(^takeoverblock)(NSError *error) = ^(NSError *error){

        if (completionHandler) {
            completionHandler(error);
        }

        if (!error) {

            self.fileModificationDate = [self modDateForURL:self.fileURL];

        }

    };

    [super moveToURL:url completionHandler:takeoverblock];
}
于 2013-11-12T20:34:40.780 回答