Get selected row’s selection in UITableView.

Wondering how to find out what row the user selected in a UITableView?

It’s pretty damn simple.

You just need to implement this func:

So this gives us an indexPath which we can use along with our array to see which value was selected.

Array’s values can be read by it’s index.

So all we need to do is this:

One thing I hate about UITableViews are when you select a row, it doesn’t deselect after letting go of the row.

Add this to fix that:

tableView.deselectRow(at: indexPath, animated: true)

Now your cells will deselect after pressing them 😊