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 use self. tableView. reloadData() in order to reload your entire table or self. tableView.
reloadData() :Reloads the rows and sections of the table view. Description : Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible.
add an 'indexPath` property to the custom table cell. initialize it in cellForRowAtIndexPath. move the tap handler from the view controller to the cell implementation. use the delegation pattern to notify the view controller about the tap event, passing the index path.
You can create an NSIndexPath
using the row and section number then reload it like so:
let indexPath = NSIndexPath(forRow: rowNumber, inSection: 0) 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.
Update for Swift 3.0:
let indexPath = IndexPath(item: rowNumber, section: 0) tableView.reloadRows(at: [indexPath], with: .top)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With