次のコード例があります。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
        [namesArray removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];        
    }   
}
と
if ([nameSection count] == 0)
{
      [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
      [tableView beginUpdates];
      [indexKeys removeObjectAtIndex:section];
      [tableView deleteSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
      [tableView endUpdates];
}
順序に注意してください....最初の例では、最初に配列からオブジェクトを削除し、次にテーブルビューから行を削除しています。
2 番目の例では、テーブルビューから行を削除し、次に配列からセクションを削除し、次にテーブルビューからセクションを削除しています。
これは物事を行う正しい順序ですか?それとも、最初に UI から削除してから配列を削除する必要がありますか?
私が尋ねる理由は、私が再現できないように見えるこれらのクラッシュを報告している何人かのユーザーを得ているからです:
NSInternalInconsistencyException - 無効な更新: セクション 1 の行数が無効です。更新 (0) 後の既存のセクションに含まれる行数は、更新前にそのセクションに含まれる行数と等しくなければなりません
このスタック トレースで:
1: libobjc.A.dylib  objc_exception_throw 32
2: CoreFoundation  [NSException raise:format:] 0
3: Foundation  -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 90
4: UIKit  -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] 6042
5: UIKit  -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] 254
6: UIKit  -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] 26
7: Movies  _mh_execute_header 253319
8: UIKit -[UITableView(UITableViewInternal) animateDeletionOfRowWithCell:] 84
9: CoreFoundation  -[NSObject performSelector:withObject:withObject:] 52
10: UIKit  -[UIApplication sendAction:to:from:forEvent:] 62