iphone - 滑动删除时崩溃

标签 iphone ios uitableview swipe-gesture

我在一个应用程序中有多个 UITableViews,滑动删除对所有这些 View 都工作正常。问题是,当我尝试滑过一个空单元格(底部)时,应用程序崩溃了:

 *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1914.84/UITableView.m:833
2012-03-24 16:20:03.158 [22339:707] Exception - attempt to delete row 3 from section 0 which only contains 3 rows before the update - attempt to delete row 3 from section 0 which only contains 3 rows before the update

cellForRowAtIndexPath、commitEditingStyleeditingStyleForRowAtIndexPath 都没有在崩溃前被调用,就像崩溃发生在我的任何方法有机会被调用之前。

作为引用,我在 editingStyleForRowAtIndexPath 中有这个

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ((indexPath.row == self.insertIndex && indexPath.section == [self.sections count] -1) || (indexPath.row == 0 && [sections count]==0)) { // last row of section, or only row of only section
        return UITableViewCellEditingStyleInsert;
    } else {
        return UITableViewCellEditingStyleDelete;
    }
}

更新:这实际上是一个大问题,因为当 tableview 滚动时应用程序几乎无法使用。

最佳答案

看起来这的根本原因是在刷新 TableView 时试图重新加载行。一定是某种不一致的状态导致了应用程序每次都崩溃。

关于iphone - 滑动删除时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9853364/

相关文章:

javascript - iOS 8 页面在输入焦点上跳转

ios - 核心数据加密

iphone - 一行中的多个单元格

ios - 如何将 UIDatePicker 中的日期和时间设置为 12 小时格式的 UITextField

iphone - 优化 iPhone 上的 SQLite3

iOS:CSS3 动画中断 div 上的滚动

swift - 自定义ui table view cell swift如何显示大量标签?

arrays - 获取 JSON 数据以从数组填充 TableView

ios - IOS界面生成器中模块的用途是什么?

ios - 不遵守使用 ScrollView 的 Storyboard约束