【发布时间】:2014-01-01 15:40:41
【问题描述】:
我正在使用此代码删除我的NSFetchedResultsController 中的一行。除了删除符号之外,行删除的动画效果很好。该标志保持完全可见,直到该行褪色然后突然消失。但是一切都应该消失,包括删除符号,就像在其他应用程序中一样。我又错过了什么?
这里是所有相关的方法(所有方法都被正确调用,我尝试了不同的动画类型,但也没有用)。
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
// Update the data model according to edit actions delete or insert.
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
//Adjust the indices of the remaining entries
NSArray *fetchedResults = [[self.fetchedResultsController fetchedObjects] copy];
int i = 1;
for (MainCategory *fetchedResult in fetchedResults)
{
fetchedResult.position = [NSNumber numberWithInt:i++];
}
}
}
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
if(!self.reordering){
if (!self.suspendAutomaticTrackingOfChangesInManagedObjectContext)
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeMove:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
}
}
好的,经过 10 次尝试后成功截屏 :-)
编辑:在这里您会看到问题:删除操作发生,要删除的行消失,而删除标志保持完全可见且不会消失。只有在行完全淡出后,删除标志才会立即消失。
编辑 2: 我已经缩小了范围。如果我用所有位置的新计算来评论这个循环,删除的效果和预期的一样好。但我需要更新这些职位,不是吗?或者你会怎么做?
【问题讨论】:
-
这种奇怪行为的屏幕截图可能很有用......
-
你为什么要复制获取的对象?有什么原因吗?
-
我的表中有一个属性位置(此特定类别在当前表中的位置,根据用户选择的排序)。因此,如果一个类别被删除,所有其他职位都需要更新。尝试截屏
-
但是为什么要复制已获取的对象?我想没必要……
-
但是for循环是必要的不是吗?所以我应该写 for(MainCategory *fetchedResult in [self.fetchedResultsController fetchedObjects])?
标签: ios uitableview core-data ios7 nsfetchedresultscontroller