Iphone – when to calculate heightForRowAtIndexPath for a tableview when each cell height is dynamic?

The way Apple implements UITableView is not intuitive to everyone and it’s easy to misunderstand the role of heightForRowAtIndexPath:. The general intention is that this is a faster and light-on-memory method that can be called for every row in the table quite frequently. This contrasts with cellForRowAtIndexPath: which is often slower and more memory intensive, … Read more

How to keep UITableView contentoffset after calling -reloadData

I was having trouble with this because I mess with cell sizing in my cellForRowAtIndexPath method. I noticed that the sizing information was off after doing reloadData, so I realized I needed to force it to layout immediately before setting the content offset back. CGPoint offset = tableView.contentOffset; [tableView.messageTable reloadData]; [tableView layoutIfNeeded]; // Force layout … Read more

How can I tell when UITableView has completed ReloadData?

The reload happens during the next layout pass, which normally happens when you return control to the run loop (after, say, your button action or whatever returns). So one way to run something after the table view reloads is simply to force the table view to perform layout immediately: [self.tableView reloadData]; [self.tableView layoutIfNeeded]; NSIndexPath* indexPath … Read more

How to reload data in a TableView from a different ViewController in Swift

Xcode 9 • Swift 4 Create a Notification Name: extension Notification.Name { static let reload = Notification.Name(“reload”) } You can post a notification NotificationCenter.default.post(name: .reload, object: nil) And add an observer at the view controller that you want to reload the data: override func viewDidLoad() { super.viewDidLoad() NotificationCenter.default.addObserver(self, selector: #selector(reloadTableData), name: .reload, object: nil) } … Read more

How to tell when UITableView has completed ReloadData?

The reload happens during the next layout pass, which normally happens when you return control to the run loop (after, say, your button action or whatever returns). So one way to run something after the table view reloads is simply to force the table view to perform layout immediately: [self.tableView reloadData]; [self.tableView layoutIfNeeded]; NSIndexPath* indexPath … Read more