iPhone应用程序在[self.tableView endUpdates]上崩溃

iPhone应用程序在[self.tableView endUpdates]上崩溃,iphone,uitableview,core-data,Iphone,Uitableview,Core Data,“我的表”视图显示用户列表。添加用户后刷新表视图时出现问题。我尝试了不同的代码和事件组合,现在应用程序在endUpdates调用时崩溃。该应用程序是按照配方应用程序建模的,因此用户单击“添加”按钮,然后会出现一个模式窗口,询问用户名。然后进入编辑屏幕,然后返回用户列表。当时,新用户没有出现。但是如果我导航回主屏幕,然后返回到用户屏幕,用户就会出现 以下是我的一些代码: - (void)controllerWillChangeContent:(NSFetchedResultsControl

“我的表”视图显示用户列表。添加用户后刷新表视图时出现问题。我尝试了不同的代码和事件组合,现在应用程序在endUpdates调用时崩溃。该应用程序是按照配方应用程序建模的,因此用户单击“添加”按钮,然后会出现一个模式窗口,询问用户名。然后进入编辑屏幕,然后返回用户列表。当时,新用户没有出现。但是如果我导航回主屏幕,然后返回到用户屏幕,用户就会出现

以下是我的一些代码:

    - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    sectionInsertCount = 0;
    [self.tableView beginUpdates];
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
  [self.tableView endUpdates];

}

    - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
 switch(type) {

  case NSFetchedResultsChangeInsert:
            if (!((sectionIndex == 0) && ([self.tableView numberOfSections] == 1))) {
                [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
                sectionInsertCount++;
            }

   break;
  case NSFetchedResultsChangeDelete:
            if (!((sectionIndex == 0) && ([self.tableView numberOfSections] == 1) )) {
                [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
                sectionInsertCount--;
            }

   break;
        case NSFetchedResultsChangeMove:
            break;
        case NSFetchedResultsChangeUpdate: 
            break;
        default:
            break;
 }
}

    - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
 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];
        }
  case NSFetchedResultsChangeMove:
            if (newIndexPath != nil) {

                NSUInteger tableSectionCount = [self.tableView numberOfSections];
                NSUInteger frcSectionCount = [[controller sections] count];
                if (frcSectionCount != tableSectionCount + sectionInsertCount)  {
                    [self.tableView insertSections:[NSIndexSet indexSetWithIndex:[newIndexPath section]] withRowAnimation:UITableViewRowAnimationNone];
                    sectionInsertCount++;
                }


                [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
                [self.tableView insertRowsAtIndexPaths: [NSArray arrayWithObject:newIndexPath]
                                     withRowAnimation: UITableViewRowAnimationRight];

    runEndUpdates = NO;

            }
            else {
                [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:[indexPath section]] withRowAnimation:UITableViewRowAnimationFade];
            }
   break;
        default:
   break;
 }
}
-(void)controllerWillChangeContent:(NSFetchedResultsController*)控制器{
sectionInsertCount=0;
[self.tableView开始更新];
}
-(void)controllerDidChangeContent:(NSFetchedResultsController*)控制器{
[self.tableView endUpdates];
}
-(void)控制器:(NSFetchedResultsController*)控制器didChangeSection:(id)sectionInfo atIndex:(nsInteger)ChangeType的sectionIndex:(NSFetchedResultsChangeType)类型{
开关(类型){
案例NSFetchedResultsChangesInsert:
如果(!((sectionIndex==0)和([self.tableView numberOfSections]==1))){
[self.tableView insertSections:[NSIndexSet IndexSetWithiIndex:sectionIndex]带RowAnimation:UITableViewRowAnimationFade];
sectionInsertCount++;
}
打破
案例NSFetchedResultsChangeDelete:
如果(!((sectionIndex==0)和([self.tableView numberOfSections]==1))){
[self.tableView deleteSections:[NSIndexSet IndexSetWithiIndex:sectionIndex]带RowAnimation:UITableViewRowAnimationFade];
分段插入计数--;
}
打破
案例NSFetchedResultsChangeMove:
打破
案例NSFetchedResultsChangeUpdate:
打破
违约:
打破
}
}
-(void)控制器:(NSFetchedResultsController*)控制器didChangeObject:(id)索引路径中的一个对象:(NSIndexPath*)变更类型的indexPath:(NSFetchedResultsChangeType)类型newIndexPath:(NSIndexPath*)newIndexPath{
开关(类型){
案例NSFetchedResultsChangesInsert:
[self.tableView insertRowsAtIndexPaths:[NSArray arraywhithobject:newindexath]with rownanimation:uitableviewrownanimationfade];
打破
案例NSFetchedResultsChangeDelete:
[self.tableView deleteRowsatindExpath:[NSArray arrayWithObject:indexPath]带RowAnimation:UITableViewRowAnimationFade];
打破
案例NSFetchedResultsChangeUpdate:{
[self.tableView重新加载rowsatindexpath:[NSArray arraywhithobject:indexPath]带rownanimation:uitableviewrownanimationfade];
}
案例NSFetchedResultsChangeMove:
if(newIndexPath!=nil){
NSInteger tableSectionCount=[self.tableView numberOfSections];
NSU整数frcSectionCount=[[controller sections]count];
if(frcSectionCount!=表SectionCount+sectionInsertCount){
[self.tableView insertSections:[NSIndexSet indexetwithindex:[newIndexPath节]]带行动画:UITableViewRowAnimationNone];
sectionInsertCount++;
}
[self.tableView deleteRowsatindExpath:[NSArray arrayWithObject:indexPath]带RowAnimation:UITableViewRowAnimationFade];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationRight];
runEndUpdates=否;
}
否则{
[self.tableView重新加载节:[NSIndexSet indexetwithindex:[indexPath节]]带行动画:UITableViewRowAnimationFade];
}
打破
违约:
打破
}
}
我几乎要崩溃了。CoreData一直是应用程序开发中最令人沮丧的部分。我应该切换到SQLLite吗?还是我还有同样的问题


谢谢

尝试调用controllerdChangeContent内部的
[self.tableview reloaddata]

根据我的经验,它必须在开始更新和结束更新之间插入或删除一些行或节。如果在BeginUpdate和EndUpdate之间未插入或删除行或节,则会崩溃

而且,如果节号和行号不正确,它也会崩溃。
因此,它需要非常仔细地编码。

今天我遇到了同样的问题

问题出在我的源代码中-其中一个UITableViewDataSource函数使用了无效对象(不是CoreData对象,简单数组,我忘记保留),这导致了崩溃。不幸的是,这在调用堆栈中并不清楚,控制台中没有提供任何消息


因此,原因可能是您实现的UITableViewDataSource协议。

我在同一地点看到了崩溃,但原因不同。我还会看到这种奇怪的行为,即表视图滚动会慢到爬行,并且基本上没有响应。这背后的原因是一种整洁和有趣的,所以我想我会分享它

我的表视图有一系列按日期排序的事件。每次从web API 50查询事件。每次进行新查询时,获取的结果都会更新,新的单元格也会进入动画。早些时候,我注意到当添加新行时会有很多奇怪的变化,但这似乎是以后需要优化的事情

应用程序中的事件可以保存,并且表视图可以在所有事件和保存的事件之间进行过滤。有一次我只是点击过滤器在所有事件和保存的事件之间来回切换,我注意到在某一天切换回“所有事件”视图时,它们会被重新排列

哦,我还需要一个开始时间描述符。这将使应用程序更易于使用

哦,糟了!我打赌这就是为什么它也会崩溃的原因!因为每次更新基本上都是因为