2

誰かが私のコードの問題を示唆できますか.....

self.modleClass.foldersAray には 1 つのオブジェクトがあり、tableview には 1 つのセクションと 1 つの行があります

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        // Delete the row from the data source
        [self.tableview setEditing:YES animated:YES];

        [self.modleClass.foldersAray removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YEs];

        [tableView reloadData];
   }
}

以下のようにエラーが発生しています。

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
4

5 に答える 5

3

このようにしてください、

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

      if (editingStyle == UITableViewCellEditingStyleDelete) {

          [self.modleClass.foldersAray removeObjectAtIndex:indexPath.row];

          [tableView reloadData];
      }
}

それで十分です........。

于 2013-02-22T12:19:19.573 に答える
2

tableView が に基づいているfoldersAray場合、この配列からオブジェクトを削除して tableview をリロードすると、このセルが削除されます。次の行を削除できます。

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YEs];
于 2013-02-22T12:23:39.897 に答える
1

このエラーは、データソース(データ、ディクショナリ、または使用するものを含む配列)を更新する必要があることを意味します

例:削除する前に5つのセルがあり、dataArrayに5つのオブジェクトがあります。を呼び出す前にdeleteRowsAtIndexPaths:、このセルに関連付けられているオブジェクトをdataArrayから削除してから、を呼び出す必要がありますdeleteRowsAtIndexPaths:。また、代わりに使用し[tableView reloadData]、使用します

[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];

PSデータソースからオブジェクトを削除しているので、注意深く確認してください。何かを見逃している可能性があります。

于 2013-02-22T12:18:54.253 に答える
1

アニメーションが必要な場合はこれを試してください。アニメーションが必要ない場合は、@MountainLionの回答を使用してください。

 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
 forRowAtIndexPath:(NSIndexPath *)indexPath  {

       if (editingStyle == UITableViewCellEditingStyleDelete) 
         {
             [self.modleClass.foldersAray removeObjectAtIndex:indexPath.row];
             [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationFade];
       } 
 }

ナビゲーションに編集ボタンがある場合は、

[self.tableView setEditing:YESアニメーション:YES];

メソッド内で編集を開始します。

于 2013-02-22T12:31:05.733 に答える