ios - [UITableView _endCellAnimationsWithContext :],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UITableView.m:1716

标签 ios objective-c uitableview

我正在项目中实现一个可编辑的表格 View 。当我点击左侧滑动后显示的红色 Delete 按钮时,应用程序崩溃了。控制台日志在这里:

*** -[UITableView _endCellAnimationsWithContext:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UITableView.m:1716 断言失败

在我的表格 View 中,有很多部分,但每个部分只有一行,因为我需要部分标题来分隔每个单元格。这是我的 UITableViewDelegateUITableViewDataSource 的实现。

#pragma mark - Delegate Methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 15.f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyNewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellReuseID forIndexPath:indexPath];

    // Configure the cell...
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell setCellWithModel:self.dataSource[indexPath.section]];

    return cell;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [self.dataSource removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

最佳答案

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 删除该行后仍然返回 1。

您必须删除该部分

[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade]

关于ios - [UITableView _endCellAnimationsWithContext :],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UITableView.m:1716,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36738459/

相关文章:

ios - CollectionView Segue 在接收 ViewController 时发现 nil

ios - 为什么在没有 ARC 的 Xcode 中切换线程时我的对象自行释放?

ios - Google Analytics - 如何使用 UIPageViewController 强制执行独特的屏幕 View

ios - Cell 原型(prototype)的数量超过了 tableview 的高度

ios - MKMapView 自行缩小

ios - 如何手动设置在应用程序委托(delegate)中显示哪个 Storyboard View

objective-c - 如何使用kiwi测试函数调用的参数?

objective-c - Objective-C:尝试在UIScrollView中实现自己的拖动,遇到了很多问题

ios - 滚动 UICollectionView 会导致父 UIView 中的 UITableView 将 Collection View 推出 Frame

iphone - 选择 UITableViewCell AccessoryView,与选择行分开