私はプロジェクトで編集可能なテーブルビューを実装しています。左のスワイプの後に赤色のDelete
ボタンが表示されると、Appがクラッシュしました。コンソールログはここにある:私のテーブルビューで[UITableView _endCellAnimationsWithContext:]、/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UITableView.m:1716
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.60.7/UITableView.m:1716
私は、各セルを分離するためにセクションヘッダーを必要とするので、そこに多くのセクションがありますが、一つだけの行とそれぞれ。ここに私の実装はUITableViewDelegate
とUITableViewDataSource
です。あなたが行を削除した後
#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];
}
}
を削除する必要があります。各セクションの行が1つしかない場合は、セクション「ビュー」をテーブルセルの一部として統合することを検討すると、はるかに単純なテーブルになります。 – NKorotkov