Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27201

UITableView won't display delete button

I have implemented these methods:

 func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
  {
    return true
  }

  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {

    if (editingStyle == UITableViewCellEditingStyle.delete) {
      showAlertToDeleteDevice()
    }
  }

and set breakpoints into it, but there is no call back of these function. -cellForRowAtIndexPath and -didSelectRowAtIndexPath functions works perfect which means that all is good with dataSource and Delegate connection.

What can be a problem? Because I don't see delete button by swiping. In the same time for I see delete button for my other table.

Upvotes: 1

Views: 175

Answers (2)

gasho
gasho

Reputation: 1931

You have to implement

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?

Upvotes: 1

Vitali Eller
Vitali Eller

Reputation: 125

You use wrong function.

override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
}

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if (editingStyle == UITableViewCellEditingStyle.Delete) {
        // delete action
    }
}

Upvotes: 1

Related Questions