2012-02-22 4 views
1

私はBarButtonアイテムを持っていて、編集モードのときはEdit、編集モードの場合はDoneです。ユーザーが編集をクリックすると、editpressメソッドが実行されます(コードを参照)。テーブルからセルを削除する - コード付き - ロジック問題あり

これで、commitEditingStyle、およびセルとデータ(セルにデータを追加するために使用される配列からの)が削除されます。

問題点:削除をクリックすると、セルがテーブルから正しく削除されます。しかし、細胞をロードするために使用される配列からではありません。私がcommitEditingStyleにデバッグポイントを置いたとき、私は最初にdeleteをクリックするとそのコードを実行します。第2、第3などのレコードを削除すると、このコードブロックは実行されません。どうしてこれなの ?

commitEditingStyle[self.tableView setEditing:YES animated:YES];のレコードを追加していません。それが欠陥なのか?

注:私は(gurantted、と私はそれを投稿didntの理由です)、同じロジックが他のプログラムで動作するため、アレイ・ロジックから私の削除は、間違っているとは思わない

-(void) editpress:(id)sender{ 
     UIBarButtonItem *editButton = (UIBarButtonItem*)self.navigationItem.leftBarButtonItem;  
     if (!self.tableView.editing) { 
      [self.tableView setEditing:YES animated:YES]; 
      UIButton *rbut= [UIButton buttonWithType:UIButtonTypeCustom]; 
      [rbut setImage:rightImage forState:UIControlStateNormal];  
      [rbut addTarget:self action:@selector(editpress:) forControlEvents:UIControlEventTouchUpInside];   
      UIBarButtonItem *rBarButDone = [[UIBarButtonItem alloc] initWithCustomView:rbut]; 
      self.navigationItem.rightBarButtonItem = rBarButDone;  
     } 
     else { 
      [self.tableView setEditing:NO animated:YES]; 
      UIButton *rbut= [UIButton buttonWithType:UIButtonTypeCustom]; 
      [rbut setImage:rightImage forState:UIControlStateNormal];    
      [rbut addTarget:self action:@selector(editpress:) forControlEvents:UIControlEventTouchUpInside];   
      UIBarButtonItem *rBarButEdit = [[UIBarButtonItem alloc] initWithCustomView:rbut]; 
      self.navigationItem.rightBarButtonItem = rBarButEdit; 
     } 
    } 


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (editingStyle == UITableViewCellEditingStyleDelete) {   
     [self.tableView beginUpdates]; 
     // I write the logic to delete the record from the array and the table here.   
     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:YES]; 
     [self.tableView endUpdates]; 
    } 
    else if (editingStyle == UITableViewCellEditingStyleInsert) { 
     // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
    } 
} 
+0

オブジェクトはデータソース配列から削除されていないと言いました。 [self.tableView reloadData]を使用しましたか? – karim

+0

はい、私はまた、 'commitEditingStyle'が最初に実行されることを述べました – shajem

+0

配列からオブジェクトを削除するコードを投稿する必要があります。それがあなたの問題です。 –

答えて

0

コード明らかに実行されていますcommitEditingStyleただし、削除した後、cellForRowAtIndexPathは削除された行の正しいデータを返しますか?ダウンロードした内部配列からそのデータを読み取っている場合は、その内部配列から項目を削除する必要があります。別のソースから読んでいる場合は、ソースが正しいデータを送信していることを確認するか、行を削除した後にソースをリフレッシュする必要があります。どちらの場合でも、データを削除するために "Webサービス"が行っていることは、新しいデータでセルをリフレッシュすることではありません。また、numberOfRowsInSection:メソッドで1つ少ないレポートする必要があります。

関連する問題