2

アプリにいくつかの UITableView があり、スワイプして削除すると、それらすべてで正常に機能します。問題は、空のセル (下部) をスワイプしようとすると、アプリが次のようにクラッシュすることです。

 *** 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, commitEditingStyleクラッシュの前に呼び出されることも呼び出されることもありませんeditingStyleForRowAtIndexPath。私のメソッドが呼び出される前にクラッシュが発生するようです。

参考までに、私はこれを持っています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;
    }
}

更新:テーブルビューがスクロールするとアプリが事実上使用できなくなるため、これは実際には大きな問題です。

4

2 に答える 2

11

これの根本的な原因は、更新中にテーブルビューの行をリロードしようとしたことのようです。ある種の一貫性のない状態が発生し、毎回アプリがクラッシュしたに違いありません。

于 2012-03-25T17:14:10.733 に答える
0

解決:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
//    tableView.isEditing ? NSLog(@"show edit controls"):NSLog(@"don't show edit controls");

    if(tableView.isEditing){
        return NO;
    }else{
        return YES;
    }
}
于 2015-03-16T12:26:26.047 に答える