iPhone应用程序崩溃[self.tableView endUpdates] [英] iPhone app crashing on [self.tableView endUpdates]

查看:3243
本文介绍了iPhone应用程序崩溃[self.tableView endUpdates]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格视图显示了用户列表。我在添加用户后刷新我的表视图有问题。我试过不同的代码和事件的组合,现在应用程序崩溃的endUpdates调用。该应用程序在食谱应用程序后建模,因此用户单击添加按钮,然后出现一个模态窗口,要求用户名称。然后它进入编辑屏幕,然后返回到用户列表。此时,新用户没有显示。但如果我导航回到主屏幕,然后回到用户屏幕,用户会出现。

My table view shows a list of users. I'm having issues refreshing my table view after adding a user. I've tried different combinations of code and events and now the app is crashing on the endUpdates call. The app is modeled after the recipe app, so a user clicks the add button, and then a modal window appears asking for the users name. Then it goes to the edit screen, and then back to the list of users. At that point, the new user wasn't showing up. But if I navigated back to the main screen, and then back to the users screen, the user would appear.

以下是我的部分代码:

    - (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;
 }
}

我几乎处于一个突破点。 CoreData一直是应用程序开发中最令人沮丧的部分。我应该切换到SQL Lite?

I'm almost at a breaking point with this. CoreData has been the most frustrating part of app development. Should I just switch to SQL Lite? Or will I still have the same issues?

谢谢!

推荐答案

今天我有同样的问题。

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

The problem was in my source code - one of UITableViewDataSource functions used invalid object (not CoreData object, simple array, which I forgot to retain), this caused crash. Unfortunately this was not clear from the call stack, no message was provided in the console.

所以原因可能在您的UITableViewDataSource协议的实现。

So the reason might be in your implementation of UITableViewDataSource protocol.

这篇关于iPhone应用程序崩溃[self.tableView endUpdates]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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