EditButton

| コメント(0) | トラックバック(0)

「EditButton」はUIBarButtonItemで生成しなくても、以下のコードですぐに追加できる。

self.navigationItem.leftBarButtonItem=self.editButtonItem;

追加されたボタンをタップすると、UITableViewControllerのサブクラスでは、以下のデリゲートメソッドが呼び出され、テーブルビューのセルアイテムが削除できる。デフォルトではコメントアウトされている。
その際、削除対象のデータソース(主に配列)を追記するしなければならない(太字部分)。ちなみに「members」はNSMutableArrayクラスのインスタンス。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
   
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source.
        [appDelegate.members removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }  
    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)

トラックバックURL: http://www.ayabin.jp/mt5/mt-tb.cgi/83

コメントする

このブログ記事について

このページは、webmasterが2010年11月28日 21:51に書いたブログ記事です。

ひとつ前のブログ記事は「NSMutableArrayの初期化」です。

次のブログ記事は「警告local declaration...」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。