Member-only story

Swipe to Delete Rows for UITableView iOS

Mr.Javed Multani
2 min readOct 3, 2020

--

I always think it is nice to have a very simple, self-contained example so that nothing is assumed when I am learning a new task. This answer is that for deleting UITableView rows. The project performs like this:

Add the Code

Create a new project and replace the ViewController.swift code with the following.

import UIKitclass ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {// These strings will be the data for the table view cellvar animals: [String] = ["Horse", "Cow", "Camel", "Pig", "Sheep", "Goat"]
let cellReuseIdentifier = "cell"
@IBOutlet var tableView: UITableView!
override func viewDidLoad() { super.viewDidLoad()// It is possible to do the following three things in the Interface Builder
// rather than in code if you prefer.
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier:cellReuseIdentifier)
tableView.delegate = self
tableView.dataSource = self
}// number of rows in table viewfunc tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.animals.count}// create a cell for each table view rowfunc tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {let cell:UITableViewCell =…

--

--

Mr.Javed Multani
Mr.Javed Multani

Written by Mr.Javed Multani

Software Engineer | Certified ScrumMaster® (CSM) | UX Researcher | Youtuber | Tech Writer

No responses yet