BobRon BobRon - 11 months ago 34
Swift Question

Refresh certain row of UITableView based on Int in Swift

I am a beginning developer in Swift, and I am creating a basic app that includes a UITableView. I want to refresh a certain row of the table using:

self.tableView.reloadRowsAtIndexPaths(paths, withRowAnimation: UITableViewRowAnimation.none)

and I want the row that will be refreshed to be from an Int named rowNumber

The problem is, I don't know how to do this and all the threads I've searched are for Obj-C

Any ideas?


You can create an NSIndexPath using the row and section number then reload it like so:

var indexPath = NSIndexPath(forRow: rowNumber, inSection: 0)
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)

In this example, I've assumed that your table only has one section (i.e. 0) but you may change that value accordingly.