Dave
Dave

Reputation: 12216

UITableView Swipe Not Called After editActionsForRowAt returns [ ]

I've been using editActionsForRowAt to create the built-in swipe left functionality to reveal quick-access buttons, like this:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    print("Is this working?")
    //Code to create UITableViewRowAction buttons
    return [button1, button2]
} 
func tableView (_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    //I read I need this, so I have it
    return true
}
func tableView (_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    //I read I need this, so I have it
}

Now my whole table, including the swipe, works great. Until...

My editActionsForRowAt function has code where if the user swipes a cell that's expanded (by default they're 50, but users can tap to expand the height) then editActionsForRowAt returns [], an empty array. I do that because I don't want really tall cells showing stretched out buttons.

After that, even after closing, swiping a cell (any cell) doesn't even call editActionsForRowAt. I checked by adding a print-line right at the beginning of that function and it doesn't print no matter what I do after swiping an expanded cell and returning [].

Any ideas on how to fix this?

Upvotes: 2

Views: 2019

Answers (1)

rmaddy
rmaddy

Reputation: 318955

Instead of returning an empty array from editActionsForRowAt, you should return false from canEditRowAt when a given row isn't editable.

Upvotes: 5

Related Questions