Add swipe to delete UITableViewCell

后端 未结 25 1612
暖寄归人
暖寄归人 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:26

    I used tableViewCell to show multiple data, after swipe () right to left on a cell it will show two buttons Approve And reject, there are two methods, the first one is ApproveFunc which takes one argument, and the another one is RejectFunc which also takes one argument.

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
        let Approve = UITableViewRowAction(style: .normal, title: "Approve") { action, index in
    
            self.ApproveFunc(indexPath: indexPath)
        }
        Approve.backgroundColor = .green
    
        let Reject = UITableViewRowAction(style: .normal, title: "Reject") { action, index in
    
            self.rejectFunc(indexPath: indexPath)
        }
        Reject.backgroundColor = .red
    
    
    
        return [Reject, Approve]
    }
    
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    func ApproveFunc(indexPath: IndexPath) {
        print(indexPath.row)
    }
    func rejectFunc(indexPath: IndexPath) {
        print(indexPath.row)
    }
    

提交回复
热议问题