Add swipe to delete UITableViewCell

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

    @available(iOS 11.0, *)
        func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    
            let editAction = UIContextualAction.init(style: UIContextualAction.Style.normal, title: "Edit", handler: { (action, view, completion) in
                //TODO: Edit
                completion(true)
                self.popUpViewPresent(index:indexPath.row)
            })
    
            let deleteAction = UIContextualAction.init(style: UIContextualAction.Style.destructive, title: "Delete", handler: { (action, view, completion) in
                //TODO: Delete
                completion(true)
                self.deleteTagAction(senderTag:indexPath.row)
            })
            editAction.image = UIImage(named: "Edit-white")
            deleteAction.image = UIImage(named: "Delete-white")
            editAction.backgroundColor = UIColor.gray
            deleteAction.backgroundColor = UIColor.red
    
            let config = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
            config.performsFirstActionWithFullSwipe = false
            return config
        }
    

提交回复
热议问题