delete a row in table view in swift

前端 未结 9 1941
萌比男神i
萌比男神i 2021-02-05 22:38

I am trying to delete a row in table view. I have implemented the required methods but when i am swiping the row horizontally no delete button is coming. I have searched and I h

9条回答
  •  遇见更好的自我
    2021-02-05 22:42

    for swift 3

    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        if editingStyle == UITableViewCellEditingStyle.delete {
            dataHandler.deletePeripheral(indexPath.row) 
            tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
            // - OR -
            // mTableView.reloadData() //mTableView is an outlet for the tableView
        }
    }
    

提交回复
热议问题