2009-10-23 84 views
0

我有一個視圖,它有它自己的導航欄和一個tableview。我想在該表格視圖中編輯&刪除項目。我已經在導航欄上放置並編輯按鈕。使用自定義導航項在tableview中編輯

self.navItem.leftBarButtonItem = self.editButtonItem; 

也有這樣的一種方法。

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

    if(editingStyle == UITableViewCellEditingStyleDelete) { 

     //Get the object to delete from the array. 
     //Delete the object from the table. 
     [self.tblView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    } 
} 

但是當我點擊該按鈕,沒有在tableview中的項目轉向與紅色標記圖標。只是編輯按鈕的標題更改爲「完成」。

應該是什麼問題?

回答

0

這是一個UIViewController,還是一個UITableViewController?它會出現(從附加代碼中的self.tblView)您使用的是標準的UIViewController。在這種情況下,您必須在您的視圖控制器中實現setEditing:animated:這反過來應該在您的表視圖中調用它。

+0

是的我在UIVIewController中放置了一個UITableView。還有一個導航欄。所以,如果可能的話,請你詳細解釋一下這個例子。 – 2009-10-24 06:06:10