Search code examples
iosuitableviewswipe

iOS - How To Give A Peek At The "Swipe To Delete" Action On A Table View Cell?


When a certain Table View Controller displays for the first time, how to briefly show that the red “swipe to delete” functionality exists in a table row?

The goal of programmatically playing peekaboo with this is to show the user that the functionality exists.

Environment: iOS 11+ and iPhone app.

Here's an image showing the cell slid partway with a basic "swipe to delete" red action button. Showing delete action under table cell via partial swipe

A fellow developer kindly mentioned SwipeCellKit, but there’s a lot to SwipeCellKit. All we want to do is briefly simulate a partial swipe to let the user know the "swipe to delete" exists. In other words, we want to provide a sneak peak at the delete action under the cell.

In case it helps, here's the link to the SwipeCellKit's showSwipe code Here is a link with an example of its use.

I looked at the SwipeCellKit source code. It's not clear to me how to do it without SwipeCellKit. Also, Using SwipeCellKit is not currently an option.

Googling hasn't helped. I keep running into how to add swipe actions, but not how to briefly show the Swipe Actions aka UITableViewRowAction items that are under the cell to the user.

How to briefly show this built in "swipe to delete" action to the user?


Solution

  • I'm pretty sure this can't be done. The swipe actions are contained in a UISwipeActionPullView, which contains UISwipeStandardAction subviews, both of which are private. They are also part of the table view, not the cell, and they're not added unless a gesture is happening, so you can't just bump the cell to one side and see them there.

    Outside of UI automation tests, it isn't possible to simulate user gestures without using private API, so you can't "fake" a swipe and then show the results to the user.

    However, why bother doing it "properly" when you can cheat? It shouldn't be too hard to bounce the cell's content view slightly to the left, and bounce in a red box (not so far that you can see text, to avoid localisation issues), then return to normal. Do this on the first load of the table view, and stop doing it after N times or after the user has proven that they know how this particular iOS convention works.