Add swipe to delete UITableViewCell

后端 未结 25 1588
暖寄归人
暖寄归人 2020-11-30 17:50

I am making a CheckList application with a UITableView. I was wondering how to add a swipe to delete a UITableViewCell.

This is my ViewCont

25条回答
  •  醉梦人生
    2020-11-30 18:09

    just add these assuming your data array is 'data'

    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if (editingStyle == UITableViewCellEditingStyle.delete) {
            // handle delete (by removing the data from your array and updating the tableview)
            if let tv=table
            {
    
    
    
                data.remove(at: indexPath.row)
                tv.deleteRows(at: [indexPath], with: .fade)
    
    
    
            }
        }
    }
    

提交回复
热议问题