2011-02-05 74 views
1

我試圖設置一個UITableView,我可以編輯。我有以下方法實施:可編輯的UITableView

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 

但我不知道如何將編輯鏈接到我的UINavigationBar中的編輯按鈕。這是我的按鈕項目:

UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" 
                   style:UIBarButtonSystemItemEdit 
                   target:nil 
                   action:@selector(editButtonSelected:)]; 

我該如何得到這個工作?

回答

2

我已經有很多成功的只是使用標準的編輯按鈕:

self.navigationItem.leftBarButtonItem = self.editButtonItem; 

與您的代碼的問題是,你沒有設定一個目標。如果editButtonSelected:選擇器位於您正在設置的視圖控制器中,請使用像這樣的「self」:

UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonSystemItemEdit target:self action:@selector(editButtonSelected:)]; 
+0

但是那麼我的editButtonSelected方法應該是什麼樣子? – CodeGuy 2011-02-05 21:07:59