t0a*_*0a0 18 objective-c uitableview ios ios8
在ios8上,我正在使用核心数据表视图控制器,删除行后,我的部分页脚视图突然一直向下到底部UITableView
.当我滚动表格视图时,页脚视图会返回到它的位置.如何解决这个问题,为什么会发生这种情况?
以下是代码以防万一.
- (void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
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:UITableViewRowAnimationNone];
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;
}
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
if (self.beganUpdates)
{
[self.tableView endUpdates];
}
}
Run Code Online (Sandbox Code Playgroud)
我刚刚遇到了同样的问题。当我使用 insertRowsAtIndexPaths.. 时,页脚转到底部。还注意到,如果您在表视图上调用 reloadData ,它将解决问题,所以我这样做了:
[CATransaction begin];
[CATransaction setCompletionBlock: ^{
// Code to be executed upon completion
[tableView reloadData];
}];
[tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationLeft];
[CATransaction commit];
Run Code Online (Sandbox Code Playgroud)
它所做的只是在插入动画完成时重新加载表格...这不是真正的解决方案,更像是避免问题,但它隐藏了问题,直到有人解释为什么会发生这种情况以及如何解决它...
归档时间: |
|
查看次数: |
4630 次 |
最近记录: |