在我的應用程序中,我需要使用UIViewController
來控制我的tableView而不是UITableViewController
(因爲我需要在我的tableView下面的額外視圖)。我已經成功實現了視圖控制器(以及委託和數據源),但是現在我需要在用戶在單元格上從左到右滑動時在我的UITableViewCell
上獲得正確的行爲。模仿UITableViewControllers行爲tableView:willBeginEditingRowAtIndexPath:在UIViewController
當用戶點擊編輯按鈕(顯示重排拖動手柄,以及使刪除確認顯示的小「 - 」按鈕)時所需的行爲很容易做到。我只是不喜歡這在我的視圖控制器:
- (void)setEditing:(BOOL)isEditing animated:(BOOL)animated {
[super setEditing:isEditing animated:animated];
[self.tableView setEditing:isEditing animated:animated];
}
但我無法弄清楚如何使刪除確認顯示,如果用戶從左至右細胞刷卡。這是我在tableView:willBeginEditingRowAtIndexPath:
已經得到了現在:
- (void)tableView:(UITableView *)aTableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
// Tell the cell to do its custom animations
[[self.tableView cellForRowAtIndexPath:indexPath] setEditing:YES animated:YES];
// set the viewControllers editing to YES, thus changing the editButton to a doneButton
self.editing = YES;
}
有了這個代碼,它應該和細胞做它的動畫騰出空間刪除確認的editButton變爲doneButton,但刪除確認本身不顯示。
我的問題:如何在指定的tableviewCell上顯示刪除確認?
注意:如果您希望編輯按鈕返回到完成狀態(如果用戶使刪除按鈕消失(不按下done按鈕)),則應該只實現tableView:didEndEditingRowAtIndexPath:其中您設置了self.editing = NO – Sorig 2010-11-14 12:24:56