UITableView Delete Row

前端 未结 2 860
孤城傲影
孤城傲影 2021-01-22 21:57

I am making a table view and I want to make a function where you can delete a row by swiping right and tapping the delete button. Me and my teacher have tried for about half an

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-22 22:26

    This swift function can delete a row by swiping right and tapping the delete button. Actually this function delete item from items array then delete row. In addition this row removed from tableView.

    override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == UITableViewCellEditingStyle.delete {
            // your items include cell variables
            items.remove(at: indexPath.row)
            tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
        }
    }
    

提交回复
热议问题