我正在显示来自CoreData
用作容器的UITableView
数据。删除一行的代码运行良好,但我的实现让我觉得不够优雅。有没有更好的办法?NSFetchedResultsController
NSManagedObjects
下面的代码说明了删除事件:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[myContext deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];
if (![myContext save:&error]) {
// Error handling
}
fetchedResultsController = nil;
if (![[self getFetchedResultController] performFetch:&error]) {
// Error handling
}
[tableView reloadData];
}
}
我设置fetchedResultsController
为nil
并执行另一次获取以更新新内容。
我担心的是,我在各种论坛上看到了暗示上下文的变化应该自动引起 fetchedResultsController 变化的参考资料,也许第二次获取是不必要的。在这一点上,我还没有实现部分。
另一个问题是代码只是让行消失而没有任何动画。
可以引入一些流畅的动画吗?