2
我試圖做到以下幾點:的UITableViewCell顯示刪除按鈕自來水
- 當用戶點擊表視圖的列。它顯示刪除按鈕。
- 當刪除按鈕可見並且用戶在行上點擊時。細胞恢復正常狀態。
截至目前,我可以透露swipe left
上的刪除按鈕並執行相應的操作。 Item-2是默認行爲。
所以只剩下要做的事情是以編程方式顯示刪除按鈕。
我曾嘗試以下:
- 在
didSelectRow
cell.setEditing(true, animated: true)
但是這似乎並沒有產生任何影響。 - 將tableview.setEditing設置爲true會使紅色刪除圖標從左側顯示,點擊這些圖標後,顯示右側的按鈕。但這不是我想要的。
如前所述,按鈕在左側滑動顯示。所以,我相信我下面的函數得到正確實施:
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]?
即使試圖執行以下操作:
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle
但同樣沒有效果。
那麼有沒有一種方法來實現我想要實現的行爲?
謝謝,它爲我節省了很多時間。 – santhu