I have a UITableView with a custom UITableViewCell. In cellForRowAtIndexPath, I assign a font to a label in every cell, since the user can change font size at any time. To change font size, the user clicks a button below the tableview, which dislays another view with settings. Once they have chosen a font size and click done, that view goes away and the tableview displays again. I display one cell per viewing area. So the user doesn't see the font change until he scrolls to the next cell. The current cell is the one I'd like to update.
I've tried reloadData from the settings screen but that didn't work. The tableview is a UITableViewController but viewWillAppear never fires once the settings screen goes away. I've tried making the custom cell a property of the tableview so it can be accessed from the settings view, then called setNeedsDisplay and setNeedsLayout. Those didn't work either. Any suggestions?
You can call [self. tableview reloadData]; on the tableview and refresh the entire table. Otherwise you can do this to refresh a single cell.
Reloading a cell/row at an IndexPath is easy and all you need to use is the reloadRows(at:, with:) .
If you want to reload your table view while also saving and restoring any selections, you should take a copy of the indexPathsForSelectedRows property before the reload, then re-apply those selections after calling reloadData() . With that in place, you can now call yourTableView.
In your custom UITableViewCell, call [self setNeedsLayout];
and it should repaint your cell at the next loop. I use it for asynchronous image loading since I'm pulling the image from the Web and it works swell.
For the cells that are still there you have to update the font of the label. You'll need a way to access the custom label in your custom cell.
After changing the font size do something like:
for (MyCell* cell in [theTableView visibleCells]) {
[cell.myLabel.font = newFont];
}
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