10

iOS11 introduced trailingSwipeActionsConfigurationForRowAt (and leading...). Does that mean I now have to implement

  1. the trailing/leading methods to control swiping for iOS11 AND
  2. editActionsForRowAt for iOS10?

How to get the simulator to run iOS10 simulations to see how my app behaves in the back level OS? Since everything is now iOS11, I'm not sure how my app will be in that version?

To clarify: I want actions for rows, but I don't want the default behaviour in iOS11 of performsFirstActionWithFullSwipe. If I just implement editActionsForRowAt then iOS11 does the full swipe.

2
  • 1
    download ios 10 simulator in xcode & check....ios 11 functionality not work on ios 10 Nov 2, 2017 at 5:02
  • I think the simulator is there, I just don't know how to run that instead of ios11 from xcode
    – zkon
    Nov 2, 2017 at 5:08

4 Answers 4

14

According to your requirement:

I want actions for rows, but I don't want the default behaviour in iOS11 of performsFirstActionWithFullSwipe. If I just implement editActionsForRowAt then iOS11 does the full swipe.

In iOS-10 and below,

to get the edit actions work in a UITableView, just implement the below methods:

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

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?
{
    let deleteAction = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexpath) in
        //YOUR_CODE_HERE
    }
    deleteAction.backgroundColor = .red
    return [deleteAction]
}

In iOS-11,

2 new methods were introduced to support editing in a UITableView, i.e. leadingSwipeActionsConfigurationForRowAt and trailingSwipeActionsConfigurationForRowAt.

According to Apple,

Swipe actions

These methods supersede -editActionsForRowAtIndexPath: if implemented

return nil to get the default swipe actions

So, you can implement these 2 methods to get the iOS-11 specific behaviour. Even if you don't editActionsForRowAt will be called.

If you don't want the default full swipe behaviour of edit action in iOS-11, just set performsFirstActionWithFullSwipe to false.

Example:

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
    return nil
}

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
    let deleteAction = UIContextualAction(style: .destructive, title: "Delete") { (action, view, handler) in
        //YOUR_CODE_HERE
    }
    deleteAction.backgroundColor = .red
    let configuration = UISwipeActionsConfiguration(actions: [deleteAction])
    configuration.performsFirstActionWithFullSwipe = false
    return configuration
}

Let me know if you still face any issues.

4
  • @Daniel implies that if my app is targeting iOS10+ then I need to implement both the trailing/leading... methods and the editActions... method. Is that correct?
    – zkon
    Nov 2, 2017 at 6:31
  • Yes if you want to avoid full swipe. If you can settle with that just implement editActions and it will work for both iOS-10 and iOS-11.
    – PGDev
    Nov 2, 2017 at 6:34
  • 2
    Accept and upvote the answer if it worked. Happy coding..:)
    – PGDev
    Nov 2, 2017 at 6:51
  • i am used "editActionsForRowAt" method its only showing the right side swipe only what i do it for left side swipe button.? May 28, 2018 at 14:10
7

If you want some form of row actions, you need to:

Implement just editActionsForRowAt and it will work for iOS 10, 11, 12 and 13. But it's NOT available in iOS 14 (or newer).

or:

Implement editActionsForRowAt on iOS 10, and implement the trailing/swiping methods on iOS 11 or newer - which are slightly fancier.

or:

Ignore iOS 10 and only support iOS 11 or newer trailing/swiping actions since most of your customers will likely be running iOS 11 anyway - and row actions are generally considered an optional feature anyway.


If you don't want the full swipe behavior, you can only achieve this on iOS 11 or newer where you can set performsFirstActionWithFullSwipe to false


Full swipe methods aren't available until iOS 11. They won't work in iOS 10.

0

It's declared as optional, so no, you don't have to implement it. I'm assuming the default implementation is to do nothing

1
  • I updated the question to clarify that I want actions, but don't want the full swipe behaviour that comes by default for iOS11. So if I implement just the swipe methods will actions work for iOS10 - which doesn't have these?
    – zkon
    Nov 2, 2017 at 5:09
0

From my experience, if you want an edit mode, as well as customized swiping, you do need editActions… as well as trailing/leading… on iOS 11.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.