删除CoreData对象,然后调用[tableView reloadData]会导致SIGABRT [英] Deleting a CoreData object, then calling [tableView reloadData] causes a SIGABRT

查看:88
本文介绍了删除CoreData对象,然后调用[tableView reloadData]会导致SIGABRT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我支持删除包含tableView的UIView中的行:

I'm supporting deleting rows in a UIView that includes a tableView:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
  [self.fetchedResultsController.managedObjectContext
            deleteObject:[self.fetchedResultsController
            objectAtIndexPath:indexPath]];
  NSError *error;
  if (![[self.fetchedResultsController managedObjectContext] save:&error]) {
   NSLog(@"Unresolved error %@, %@, %@", error, [error userInfo],
                    [error localizedDescription]);
  }
  else {NSLog(@"Apparently successful");}
  [self.tableView reloadData];
 }
}

当我尝试这个,我得到成功消息,然后在configureCell中的一个SIGABRT。它好像在某个地方的对象没有被删除,并且configureCell正试图呈现一个丢失的对象。 (当我重新运行应用程序时,记录消失了。)

When I try this out, I get the "Apparently successful" message in the console, but then a SIGABRT in configureCell. It's as though somewhere the object hasn't been deleted, and configureCell is trying to present a missing object. (When I re-run the app, though, the record is gone.)

任何想法?

推荐答案

你不应该有 [self.tableView reloadData] 当你使用 NSFetchedResultsController

当你删除一个对象时,右 NSFetchedResultsControllerDelegate <

When you delete an object, the right NSFetchedResultsControllerDelegate method will be called for you, where you should take care of updating your table view.

创建一个空的基于导航的应用程序

Create an empty Navigation-based Application and check the Use Core Data for Storage checkbox. What you will get is an empty project that does all this correct. It will be a good example.

这篇关于删除CoreData对象,然后调用[tableView reloadData]会导致SIGABRT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆