Add swipe to delete UITableViewCell

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

    Swift 4

    @available(iOS 11.0, *)    
    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
                let action =  UIContextualAction(style: .normal, title: "", handler: { (action,view,completionHandler ) in
                    //do stuff
                    completionHandler(true)
                    let data:NSDictionary = self.conversations[indexPath.row] as! NSDictionary
                    print(data)
                    let alert:UIAlertController = UIAlertController(title: "", message: "are you sure want to delete ?", preferredStyle: .alert)
    
                    alert.addAction(UIAlertAction(title: "CANCEL", style: UIAlertActionStyle.cancel, handler: { (action) in
                    }))
                    self.present(alert, animated: true, completion: nil)
                })
                action.image = UIImage(named: "")
                action.backgroundColor = UIColor(red: 0/255, green: 148/255, blue: 204/255, alpha: 1.0)
                let confrigation = UISwipeActionsConfiguration(actions: [action])
    
                return confrigation
            }
    

提交回复
热议问题