我想實現一個UITableView
,當我按下我的ViewController
中的按鈕時,我可以看到單元格右側的刪除按鈕,但沒有看到紅色的負圓圈細胞的左邊。讓UITableViewCell顯示沒有紅色的刪除按鈕
對此的任何想法?
我想實現一個UITableView
,當我按下我的ViewController
中的按鈕時,我可以看到單元格右側的刪除按鈕,但沒有看到紅色的負圓圈細胞的左邊。讓UITableViewCell顯示沒有紅色的刪除按鈕
對此的任何想法?
只是一個方法:
isDeleteEnabled
(或任何你的名字)來TRUE
UITableView
和cellForRowAtIndexPath
檢查爲BOOL值TRUE
然後加載所有的UITableViewCell
與它刪除按鈕定製單元 (您需要設置的選擇方法 刪除的行)通過輕觸細胞按鈕isDeleteEnabled
UITableView
,這一次在cellForRowAtIndexPath
檢查isDeleteEnabled
值 - 這將是FALSE
。所以,你需要加載正常的(或你原來的)UITableViewCells。我採用這種方法做了非常類似的事情。
另外,我還沒有公佈它的代碼有三個原因:
您不需要按鈕操作來觸發此操作。如果您實施以下代理,則可以直接輕掃並刪除單元格。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//Delete the row
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
問題是我不想刷卡。我需要按一個按鈕,然後出現刪除按鈕。但我不想讓左側的紅色減號圓出現。這可能嗎? – user481960 2013-04-24 09:32:00
在這種情況下,您將不得不編寫自己的方法。 – Mani 2013-04-24 09:43:19
我的想法,不使用按鈕但你可以刷卡,小區刪除與方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
//Use actionsheet or deleteRowsAtIndexPaths
}
}
他想刪除按鈕,但不是減號 – Firdous 2013-04-24 09:24:12
是的,我建議他刷單元格看刪除按鈕。如果他想得到他想要的只是自定義代碼。 – 2013-04-24 09:30:16
,如果你不想減號出現,需要考慮你自己的簡單解決方案比默認的一個,插入一個刪除按鈕,並提供一個動畫給它,做你想要的
覆蓋,以支持編輯表視圖。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//add code here for when you hit delete
}
}
謝謝!實際上,我決定按照你的建議手動實現它,看看它是如何發展的。 – user481960 2013-04-26 11:16:06
你的GitHub鏈接已死... – Atomix 2016-01-13 22:33:16