Add swipe to delete UITableViewCell

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

    Swift 3 with custom title supported

            func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
                    return true
                }
    
        //If you want to change title
                func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
                    return "Cancel"
                }
    
                func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
                    if (editingStyle == UITableViewCellEditingStyle.delete) {
    // you might want to delete the item at the array first before calling this function
                        tableView.deleteRows(at: indexPath, with: .automatic)
                    }
                }
    

提交回复
热议问题