2012-07-26 108 views
0

我面臨一個問題,我有一個選項卡應用程序,在該應用程序中,我將第二個控制器作爲導航控制器,然後將表視圖拖放到此處。如何使編輯功能

我的表格工作正常,從數據庫進來的所有元素。

我的問題是,我想單擊時編輯按鈕,表進入編輯模式,並允許我刪除表中的行。我無法理解我怎麼能做到這一點我想這

- (void)viewDidLoad 
{ 

     self.navigationItem.rightBarButtonItem = self.editButtonItem; 



    [super viewDidLoad]; 

它帶來的導航控制器的右側的編輯按鈕,但是當我點擊它不能在編輯模式下更改表。

我知道我必須實現這個方法,但我沒有得到什麼在這個

- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 

} 

寫上到處都是其他論壇,我覺得寫的tableview -----,這是什麼表視圖是UITableView類的實例?

幫助我的代碼的東西 請

回答

0

你必須ASIGN在以下按鈕 - (無效)viewDidLoad中

self.navigationItem.rightBarButtonItem = self.editButtonItem; 

,然後實現以下方法:

// Override to support conditional editing of the table view. 
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Return NO if you do not want the specified item to be editable. 
    return YES; 
} 

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return UITableViewCellEditingStyleNone; 
} 


- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return NO; 
} 
+0

謝謝兩位,你們的幫助...... ME A LOT – 2012-07-26 02:21:40

+0

不客氣。 – OnlyAngel 2012-07-30 21:24:49

0

你可以刪除你的setEditing:animated:或致電superUITableViewController的默認實現已經將其表格視圖置於編輯模式,因此您不必親自操作。你在這裏做的是用一個什麼都不做的方法覆蓋這個行爲。