我想在我的單元格上添加一個自定義按鈕,與滑動刪除功能做同樣的事情。所以當點擊我的自定義按鈕時,這個會隱藏起來讓官方出現紅色的「刪除」按鈕。以編程方式觸發UITableViewCell「刪除」按鈕
所以我做了這樣的事情:
/// Controller.m
///
/// @brief Delete icon button pressed. Trigger display of Delete full button
///
- (IBAction)deleteDrug:(id)sender event:(id)event {
NSIndexPath *indexPath = [self indexPathForButton:sender event:event];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell setEditing:YES animated:YES];
}
/// CustomCell.m
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
// hide/show "modify" button when entering in edit mode
switch (editing) {
case YES:
self.deleteButton.hidden = YES;
break;
case NO:
self.deleteButton.hidden = NO;
break;
default:
break;
}
}
在這一刻,當你點擊它們,但官方的紅色「刪除」按鈕並未顯示在我的自定義按鈕越來越隱藏。
做一個人知道如何處理這個?
'[tableView setEditing:YES animated:YES];'會在單元格左邊放置一個紅色圖標(允許您調出右邊的紅色「刪除」按鈕)。我不想要它。我真的希望我的自定義按鈕直接顯示右邊的紅色「刪除」按鈕。 – Yaman 2013-03-18 15:57:13
我想這是真的。它可能是因爲你試圖覆蓋預期的行爲,你可能需要去全距離並處理刪除按鈕。 – 2013-03-18 15:58:11
葉我害怕這將是唯一的方式... Thx爲你的幫助瑞安。 – Yaman 2013-03-18 16:00:59