編集/削除またはスワイプ-削除ジェスチャでアイテムを削除した後、テーブルが更新されません。[編集/削除]を実行しても、[削除]ボタンが消えません。それは押された/スタックした状態でそこにとどまります。次に[完了]をクリックすると、[削除]ボタンが消えます。このスクリーンショットは、この投稿の下部に添付されています。
私のnumberOfRowsInSectionコードは、アプリの起動時に実行されますが、アイテムの削除後には実行されません。
UITableViewControllerを使用しています。私の.hファイルの定義:
@interface BNVFavoritesTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{    
  BNVAppDelegate *appDelegate;    
  IBOutlet UITableView *myTable;
}
@property (retain, nonatomic) IBOutlet UITableView *myTable;
@end
これが私の.mファイルからの関連コードです:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"number of rows:\t%d", [appDelegate.favoritesArray count]);
    return [appDelegate.favoritesArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    //Get the object from the array.
    BNVFavorite *favoriteObj = [appDelegate.favoritesArray objectAtIndex:indexPath.row];
    //Set the name.
    cell.textLabel.text = favoriteObj.name;
    // Set up the cell
    return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    // If row is deleted, remove it from the list.
    if (editingStyle == UITableViewCellEditingStyleDelete){
        NSLog(@"before delete\t%d", [appDelegate.favoritesArray count]);        
        BNVFavorite *selectedObject = [appDelegate.favoritesArray objectAtIndex:indexPath.row];
        NSString *selectedName =  selectedObject.name;
        // delete from sqlite database
        [appDelegate removeFavoriteFromDB:selectedName];
        // delete from memory array
        [appDelegate.favoritesArray removeObjectAtIndex:indexPath.row];
        // delete in user interface
        [myTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        NSLog(@"after delete\t%d", [appDelegate.favoritesArray count]);
    }
}
削除すると、ログに「削除前」と「削除後」のメッセージが表示されますが、「行数」メッセージは表示されません。
テーブルビューのデータソースとデリゲートアウトレットは、TableViewControllerクラスに接続されています。ViewDidLoadメソッドでもこれを試してみましたが、違いはありませんでした。[myTable reloadData];私の最後にaを強制するcommitEditingStyleことも助けにはなりません。
最後に、これがその「スタック」削除ボタンのスクリーンショットです。 http://i.stack.imgur.com/ukUu0.png
数回クリックすると、NSRangeException / out of boundsエラーが発生し、fromのコードcommitEditingStyleが実行されたことを示します。