Jeremy
Jeremy

Reputation: 31

tableView(_:editActionsForRowAt:) is not called on iOS 9.3

The method tableView(_:,editActionsForRowAt:) works fine for devices running iOS 10 or above but is not called on devices running iOS 9.3

I am using

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
{
    "Code"
    return [ "various actions"]
}

Edit action works fine in all my classes when run on iOS 10 or above, but in one class it does not work at all on devices running 9.3. Using breakpoints in the code it would seem this function is not executed at all.

Upvotes: 0

Views: 1940

Answers (4)

Аλέξιος
Аλέξιος

Reputation: 21

None of these worked for me, except I tried different options. I hope it will be helpful. You have to add editing style for iOS 9, as it's none - there is nothing to show on your Storyboard.

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
    if #available(iOS 10.0, *) {
        return .none;
    } else {
        return .delete;
    }
}

Upvotes: 0

אורי orihpt
אורי orihpt

Reputation: 2644

If canEditRowAt is not getting called:

override func setEditing(_ editing: Bool, animated: Bool) {
    super.setEditing(editing, animated: animated)
    tableView.setEditing(editing, animated: animated)
}

Upvotes: 0

Jeremy
Jeremy

Reputation: 31

After a lot going back on my Git repositories, I found that:

func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
return .none
}

Was causing IOS 9.3 to not allow sliding the row to the left but allows the moveRowAt function to work. Removing the code allows both the slide & move options to work however I now have the delete button on the left for all IOS's which is not what I want

Move row selected

For now, the only solution I can see is to have two classes one for IOS 9.3 and another for 10 +. This will mean that the IOS 9.3 devices will show the delete button. Really hope there is a better solution.

Upvotes: 1

cjbatin
cjbatin

Reputation: 283

If the function isn't being called at all in your class make sure that you have set the delegate correct.

Usually this would be done in the viewDidLoad. By setting tableView.delegate = self. Also make sure you have tableView.dataSource = self. If it's working in your other view controllers I imagine there is an example there.

If you're using storyboards you can also set the delegate and dataSource in that. I'm sure it will just be a case have forgotten to do it!

You also need to make sure your class extends both UITableViewDelegate and UITableDataSource.

Upvotes: 1

Related Questions