2011-12-24 6 views
0

Storyboard内のUIView内にTableViewを実装しようとしています。 これは私が達成したものである:UIView内のTableViewのレコードを削除します。

enter image description here

は、今私は編集ボタンが、押された場合、削除のためにテーブルの行を準備することを望みます。 私はバーのウィットに、次の[編集]ボタンを置く:

//add edit button 
[buttons addObject:self.editButtonItem]; 

また私がメインビューにテーブルビューのデリゲートとデータソースを設定して、イベントが解雇されています。しかし、どのようにしてテーブルの行を削除可能にしなければならないのかを編集ボタンに伝えることはできますか?押された編集butttonため

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
        withRowAnimation:UITableViewRowAnimationFade]; 
    //some other bookkeeping stuff 
} 

追加コード:

は、このデリゲートtabelView方法があり yassa

答えて

2

、事前にありがとうございます。 「toggleEdit」の名前を必要に応じて変更します。

- (IBAction)toggleEdit:(id)sender //this method should get called when Edit is pressed 
{ 
    [self.tableView setEditing:!self.tableView.editing animated:YES]; 


//The if ... else part is optional. You might need to make some change to fit your's. 
// if (self.tableView.editing) 
//  [self.navigationItem.rightBarButtonItem setTitle:@"Done"]; 
// else 
//  [self.navigationItem.rightBarButtonItem setTitle:@"Delete"]; 
} 
+0

ご回答ありがとうございます。私は既に委任されたメソッドを実装しました。私の問題は、私のビュー内の私のテーブルに編集ボタンを参照する方法がわからないことです... – yassassin

+0

私は私の答えを更新しました。 – user523234

関連する問題