Re: [問題] 自訂刪除tableviewCell的button
※ 引述《whitefur (白毛)》之銘言:
: 如何按下在UITableViewCell的UIButton後delete該cell
: ex:以下是一個UITableView
: _____________
: | x|
: |___________|
: | x|
: |___________|
: | x|
: |___________|
: 每個cell右上角有一個UIButton
: 我想要按下該button後將該cell刪除
: 我的解法:
: 在按下button後
: 執行[self setEditing:YES animated:YES]
: (這裡的self是指UITableViewCell instance)
: 但是都沒作用....
: 請問這該如何解決呢
: 謝謝
1. 要能進入 editing mode, 你必須設定那個 cell 的 editing accessory type
2. 不過你想要的是在按下按鈕後「直接刪除」, 所以你不應該進入 editing mode
- (void)deleteTableViewRowForButton:(id)sender
{
// 拿到 button 所在的 cell
UITableViewCell *cell = [self tableViewCellForButton:sender];
UITableView *table = cell.superview;
NSIndexPath *cellIndex = [table indexPathForCell:cell];
[table beginUpdates];
[table deleteRowsAtIndexPath:@[cellIndex] animated:YES];
[table endUpdates];
}
直接刪就好了
不過要記得, 刪 cell 的時候也要同時處理你的 data source 讓它們同步...
--
"問おう、貴方が私のマスターか?"
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.32.81.146
※ 編輯: uranusjr 來自: 114.32.81.146 (01/16 08:27)
推
01/16 21:54, , 1F
01/16 21:54, 1F
推
01/17 10:09, , 2F
01/17 10:09, 2F
推
01/18 00:17, , 3F
01/18 00:17, 3F
→
01/18 00:18, , 4F
01/18 00:18, 4F
→
01/18 11:53, , 5F
01/18 11:53, 5F
→
01/18 11:54, , 6F
01/18 11:54, 6F
→
01/18 11:54, , 7F
01/18 11:54, 7F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章