How to add Swipe To Delete in UITableView using Swift

How to add Swipe To Delete in UITableView using Swift

In this tutorial, I will show you how to delete an item from an UITableView by swiping the cell to the left to reveal the Delete button.

It’s a very easy to implement and won’t take you over 2 minutes to add it to your TableView.

The only thing you have to do is add the following functions to the class where the tableview’s datasource is:

In this example, we filled we data an array named Items, and we removing the chosen item from the list when the user swipes left and press the delete button (or just swipes left all the way through).

If you want to use an image instead of a text, you can do it by changing the title to nil and adding the image like that (only for iOS 11 and above):

You can find the final project here

If you have any questions feel free to DM me on Twitter @johncodeos or leave a comment below!

Leave a Reply

avatar
  Subscribe  
Notify of

Stay Connected

Newsletter

Subcribe for weekly emails! Get my posts of the week right in your inbox!