2010-04-04 103 views
1

我有一個頂部導航欄控件的視圖。視圖處於第二級,默認情況下在左側顯示「後退」按鈕。在我看來類,我添加右側的默認導航編輯按鈕:單擊編輯按鈕後顯示添加按鈕?

self.navigationbarItem.rightButtonItem = self.editButtonItem; 

與這行代碼,編輯按鈕位於右側,當點擊它時,示圖(表視圖)在每行左邊的刪除標記變爲可編輯。之後,編輯按鈕的標題變成「完成」。所有這些都是通過內置在導航控件中的默認編輯按鈕完成的,我想。

我想在左邊添加一個添加按鈕,或者在單擊編輯時替換「後退」按鈕。我想我必須在我的視圖類中實現某種委託。這將提供一個位置來插入我的代碼,以在單擊編輯按鈕時在左側添加添加按鈕,並在完成按鈕被單擊時恢復「返回」按鈕。如果是這樣,代表是什麼?或者還有其他方法可以實現嗎?

回答

1

我做這樣的(在我的表視圖控制器):

editButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleEditing)]; 
    editButton.possibleTitles = [NSSet setWithObjects:@"Edit", @"Done", nil]; 
    self.navigationItem.rightBarButtonItem = editButton; 


- (void)toggleEditing { 
    // Keep track of whether your editing or not here 
    // and show/hide the 'add' button accordingly 
} 
+0

它看起來像您添加自定義的按鈕。刪除標記的默認行爲如何?任何方式來設置在編輯模式下的表格視圖? – 2010-04-04 05:10:30

+0

使用setEditing:animated:方法在編輯模式下設置表視圖。 – glorifiedHacker 2010-04-04 06:25:15