Objective c -[UITableView\u endCellAnimationsWithContext:]中的断言失败

Objective c -[UITableView\u endCellAnimationsWithContext:]中的断言失败,objective-c,ios,uitableview,crash,Objective C,Ios,Uitableview,Crash,希望这将是一个快速修复。我一直在努力找出我不断遇到的错误。错误列在下面,appdelagate列在下面 感谢您的帮助 谢谢 2012-04-12 21:11:52.669 Chanda[75100:f803]——在-[UITableView\u endCellAnimationsWithContext:,/SourceCache/UIKit\u Sim/UIKit-1914.84/UITableView.m:1037 2012-04-12 21:11:52.671 Chanda[75100:f8

希望这将是一个快速修复。我一直在努力找出我不断遇到的错误。错误列在下面,appdelagate列在下面

感谢您的帮助

谢谢

2012-04-12 21:11:52.669 Chanda[75100:f803]——在
-[UITableView\u endCellAnimationsWithContext:
/SourceCache/UIKit\u Sim/UIKit-1914.84/UITableView.m:1037
2012-04-12 21:11:52.671 Chanda[75100:f803]--由于未捕获的异常而终止应用程序“
nsInternalinconsistenceException
”,原因:“无效更新:第0节中的行数无效。更新(2)后现有节中包含的行数必须等于更新(2)前该节中包含的行数,加上或减去从该节中插入或删除的行数(插入1行,删除0行),加上或减去移入或移出该节的行数(移入0行,移出0行).'


我看不出你为什么要给我们看这部分代码。我假定您的错误必须与代码中的这一部分相连接

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
可能您在其中一个数据源方法中犯了错误。目前不可能确切地说什么是错误的,但我假设可能是这样的:您在
numberofrowsin部分告诉表视图,您希望保留和设置n行,然后在
cellforrowatinexpath
中,您只处理n-1行


很抱歉,这个答案不能像它应该的那样精确。如果您向我们展示您的数据源实现,那么就更容易知道发生了什么。

删除行时,请记住,在更新时,它还会检查部分,具体如下:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)theTableView

如果要删除节中最后一项的行,则需要删除整个节(否则可能会导致节计数错误并引发此异常)。

我将每个节元素放在单独的数组中。然后将它们放入另一个数组(arrayWithArray)。我的解决方案是:

[quarantineMessages removeObject : message];
[_tableView beginUpdates];
if([[arrayWithArray objectAtIndex: indPath.section] count]  > 1)
{
    [_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indPath] withRowAnimation:UITableViewRowAnimationBottom];
}
else
{
    [_tableView deleteSections:[NSIndexSet indexSetWithIndex:indPath.section]
              withRowAnimation:UITableViewRowAnimationFade];
}
[_tableView endUpdates];
就像孙子:最好不战而胜。在我的情况下,每当我看到这种错误消息(即添加或删除的行之间的差异等)。。我甚至不调试任何东西。。我只是避免在重新加载行时进行额外调用。。这是99%发生此错误的情况

这是发生此错误的常见情况:我有一个
UINavigationController
,它有一个
UITableView
,当我单击一行时,它会推送一个新的
UITableView
,依此类推。当我弹出最后一个
UITableview
并返回到它前面的
UITableview
时,这个错误总是发生在我身上,此时我对
loadIt
函数进行了不必要的调用,该函数基本上插入行并重新记录
UITableview

发生这种情况的原因是我错误地将loadIt函数放在
viewdide:animated
中,而不是
viewDidLoad
中<代码>视图显示:每次显示
UITableView
时都会调用animated
viewDidLoad
只调用一次。

我也有同样的错误

我用了下面几行

UINib *myCustomCellNib = [UINib nibWithNibName:@"CustomNib" bundle:nil];
[tableView registerNib:myCustomCellNib forCellReuseIdentifier:@"CustomNib"];
在viewDidLoad方法中注册nib,因为我有一个与同一类关联的不同nib。因此,这条线

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GBFBLoadingCell"];
返回nil,除非我在viewDidLoad中注册nib

我的问题是,我忘记在属性检查器中为我的文件“CustomNib.xib”和“CustomNib~iphone.xib”设置标识符。(或者更准确地说,我在XCode的属性检查器中键入标识符后忘记按enter键,因此新名称无法保存。)


希望这能有所帮助。

我的核心数据库也有同样的问题。如果使用多个FRC,只需在numberOfSectionsInTableView中的每个条件内重新加载tableview

别忘了更新数组,它决定了节中的行数。在设置动画并删除之前,需要对其进行更新

我们检查节中的行数是否为1,因为我们必须删除整个节

如果有人能更清楚地回答这个问题,请纠正我

[self.tableView beginUpdates];
if ([tableView numberOfRowsInSection:indexPath.section] == 1) {

   [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
} else {

   [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
[self.tableView endUpdates];

我只是在使用Swift和FRC支持的数据存储管理信息时遇到了这种情况。在delete操作中添加一个简单的检查来评估当前的indexPath.section,这样我就可以避免一个无关的调用。我想我理解为什么会出现这个问题。。。基本上,每当我的数据集为空时,我都会将消息加载到第一行。这将创建一个off by one问题,因为存在一个伪行

我的解决方案

... delete my entity, save the datastore and call reloadData on tableView
//next I add this simple check to avoid calling deleteRows when the system (wrongly) determines that there is no section.

       if indexPath.section > 0 {

        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .None)

            }

它可以是
UITableViewDataSource
协议方法之一

为了

它应该返回一个整数,该整数等于

-insertRowsAtIndexPaths:withRowAnimation:
和/或
-deleteRowsAtIndexPaths:withRowAnimation

为了

它应该返回一个整数,该整数等于

-insertRowsAtIndexPaths:withrowsanimation:
和/或
-deleteSections:withRowAnimation:
如果您像我一样使用
NSFetchedResultsController
并在后台线程中更新数据,请不要忘记在代理中开始和结束更新:

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView beginUpdates];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView endUpdates];
}

只需检查您是否调用[yourTableView reloadData];修改值数组后。

我遇到了相同的错误,在尝试使用
[tableView reloadData]
时工作正常。 这个错误实际上是在线上的

[TabView insertRowsAtIndexPaths:indexPathsArray withRowAnimation:UITableViewRowAnimationRight];
当我尝试检查indexPath值时,它们没有按要求正确

我通过更改
indexPathsArray
中的值来修复它


希望这有帮助。

您应该将代码移动到类中,并可能在后台线程中执行它。无论如何,当您尝试在没有实际值的情况下删除行时,通常会出现此错误
- numberOfSectionsInTableView:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView beginUpdates];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    [self.tableView endUpdates];
}
[TabView insertRowsAtIndexPaths:indexPathsArray withRowAnimation:UITableViewRowAnimationRight];