2012-01-14 5 views
0

テーブルビューで個々のセルに挿入ボタンと削除ボタンを追加したいと思います。UITableView setEditingによって提供される挿入ボタンと削除ボタンを追加するにはどうすればよいですか?

次のコードは、削除のために正常に動作しています。また、このボタンはナビゲーションには表示されません。

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    card = [[NSMutableArray alloc]initWithObjects:@"card1",@"Card2",@"card3",@"card4",nil]; 
    self.navigationItem.leftBarButtonItem = self.editButtonItem; 
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewItem)]; 
    self.navigationItem.rightBarButtonItem = rightButton; 


    // Uncomment the following line to display an Edit button in the navigation bar for this view controller. 
    // self.navigationItem.rightBarButtonItem = self.editButtonItem; 
} 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // Delete the row from the data source. 
     [card 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. 
    } 
} 

答えて

1

は、ナビゲーションバーの[編集]ボタンを取り除くためにそのアクション[tableview setEditing:]あなた自身を呼び出します。

は、特定の細胞ではなく、他の削除ボタンを有効にテーブルビューのデリゲートメソッドを実装するには、次の

tableView:editingStyleForRowAtIndexPath: 

をし、編集モードで削除ボタンを表示したくない行のUITableViewCellEditingStyleNoneを返し、UITableViewCellEditingStyleDeleteあなたがしたいもののために。

0

正確には何を探していますか?ナビゲーションバーに編集ボタンが表示されますか?

すでにことを持っている必要があります私には思える:その後、独自のボタンを作成

self.navigationItem.leftBarButtonItem = self.editButtonItem; 

とと:この行を取り除く

self.navigationItem.leftBarButtonItem = self.editButtonItem; 
+0

ナビゲーションバーには表示されません。各セルに挿入と削除ボタンが必要です。 – vrn

関連する問題