2

edited with extra information: I am using an app based on CoreDataTableViewController from cs193p. When I delete an instance of an entity called Position, the prepareForDeletion is called immediately. But when I call saveToURL, or when the database is being autosaved, prepareForDeletion is called again.

Is this the way it should be? can I prevent it?

4

2 回答 2

0

设置 aBOOL isDeleting并检查该进程是否已在运行。

例子

- (void) prepareForDeletion
{
    if ( isDeleting ) 
        return;


    /* handle the rest of the deleting process */
    isDeleting = YES;


    if ( /* the process has finished deleting */ )
        isDeleting = NO;
}
于 2012-06-30T01:49:43.783 回答
0

这大概就是它应该的样子。UIManagedDocument 使用两个 ManagedObjectContexts。当子上下文 (document.managedObjectContext) 保存时,它会对其父上下文进行保存。prepareForDeletion当父级保存到持久存储时,父级上下文中的对象又会立即被调用。

于 2014-12-01T02:57:27.647 回答