0

アドレスのセットを持つ配列(データソース)があり、テーブルビューはデータソースからのセルの量が2倍になるように設定されているため、奇数のセルを小さく明確にスタイル設定できます(テーブルビューをセルが分離されているように見せるため)小さなスペースで)。行を削除するときに問題が発生します。次のようにします。

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView beginUpdates];
if (editingStyle==UITableViewCellEditingStyleDelete) {
        [self DeleteAddress:[ListAddress objectAtIndex:indexPath.row/2]];

        [ListAddress removeObjectAtIndex: indexPath.row/2];
        NSIndexPath *nextIndexPath = [[NSIndexPath alloc] initWithIndex:indexPath.row+1];

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nextIndexPath,nil] withRowAnimation:UITableViewRowAnimationRight];
    }else if (editingStyle == UITableViewCellEditingStyleInsert){
         [self tableView:tableView didSelectRowAtIndexPath:indexPath];

    }
[tableView endUpdates];
}

DeleteAddressメソッドは、データベースからアドレスを削除します。デバッガーが[tableviewendUpdate]関数に到達すると、次のエラーが発生します。

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1070
NSInternalInconsistencyException
4

2 に答える 2

0

私の問題は、 nextIndexPath 変数を間違った方法で作成していたことです。次のようになっているはずです。

NSIndexPath *nextIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];

また、両方の行を同時に削除することはできませんでした。下から別々に削除する必要がありました。

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:nextIndexPath] withRowAnimation:UITableViewRowAnimationRight];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
于 2013-03-20T14:33:25.703 に答える
0

サンプル コードに従ってください。データ ソースから 1 行を削除します。お役に立てば幸いです。このコードは私のアプリで機能します。試してみてください

//  Swipe to delete has been used.  Remove the table item

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        //  Get a reference to the table item in our data array
        Pictures *itemToDelete = [self.pictureListData objectAtIndex:indexPath.row];

        //  Delete the item in Core Data
        [self.managedObjectContext deleteObject:itemToDelete];

        //  Remove the item from our array
        [pictureListData removeObjectAtIndex:indexPath.row];

        //  Commit the deletion in core data
        NSError *error;
        if (![self.managedObjectContext save:&error])
            NSLog(@"Failed to delete picture item with error: %@", [error domain]);

        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
}
于 2013-03-20T03:53:18.077 に答える