I need to update tableview cell without reloadRows and reloadData method in swift. Is It possible?
-
4It would be easier to answer if you told us _why_ you don't want to use `reloadRows` or `reloadData`? – Eimantas Jul 11 '18 at 09:27
-
@Eimantas I needed to update a only a particular cell and I am using my customized method set the height to the tableview based on rating given to a user. But if I give rating to single user other cells are getting impacted and same with reload rows – Rakesh Jul 11 '18 at 09:32
-
1https://stackoverflow.com/questions/51265234/can-we-resize-uitableviewcell-without-reloading-it – Mahendra Y Jul 11 '18 at 09:39
3 Answers
You can use tableview.indexPathsForVisibleRows
if you wanna just update the ones on the screen and the others will be updated through cellForRow
/ willDisplayCell
Then you would traditionally do something like
tableview.indexPathsForVisibleRows.forEach {
if let cell = tableview.cellForRow(at: $0) as? MyCell {
cell.configure()
}
}

- 3,103
- 22
- 28
Try this piece of code:
UIView.setAnimationsEnabled(false)
self.yourTableView.beginUpdates()
self.yourTableView.reloadSections(NSIndexSet(index:indexToBeReload) as IndexSet, with: UITableViewRowAnimation.none)
self.yourTableView.endUpdates()

- 25,419
- 17
- 47
- 88

- 31
- 4
If You want to update cell content size, You should use beginUpdates() and endUpdates() to change content size of UITableViewCell, in this case heightForRowAtindexPath will called for each cell in tableView and update height of TableviewCell. for iOS > 10, You should prefer performBatchUpdates(_:completion:) instead of beginUpdates() and endUpdates().
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
For more information
https://appengineer.in/2018/07/11/resize-uitableviewcell-size-without-fluctuation-and-jerk/
https://developer.apple.com/documentation/uikit/uitableview/1614908-beginupdates

- 1,941
- 20
- 26