Add swipe to delete UITableViewCell

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

    You can try this:

    func tableView(tableView: UITableView!, canEditRowAtIndexPath indexPath: NSIndexPath!) -> Bool {
        return true
    }
    
    func tableView(tableView: UITableView!, commitEditingStyle editingStyle:   UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) {
        if (editingStyle == UITableViewCellEditingStyle.Delete) {
            NamesTable.beginUpdates()
            Names.removeAtIndex(indexPath!.row)
            NamesTable.deleteRowsAtIndexPaths([indexPath], withRowAnimation: nil)
            NamesTable.endUpdates()
    
        }
    }
    

提交回复
热议问题