I have
class StationViewController :
UITableViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var stationTableView: UITableView!
When update the data in my data source and do
stationTableView.reloadData()
this is not immediately visible on the screen. If I scroll, tilt or do anything else which forces a repaint of the screen the updated cells are visible. I can confirm that the UITableView did do the update by calling
println("\(stationTableView.visibleCells())")
which prints the expected cells.
The rest of the setup is a UINavigationController
which has my StationViewController
as a relationship. The IBOutlet for the stationViewController
is connected to the UITableView
in the storyboard file.
I seem to need a "repaint" of the screen to make my update immediately visible. How do I do that?
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.
There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.
Implementation of adding a table view inside the cell of UItableview aka, Nested Table View. Used the Power of Autosizing table view and delegate to achieve the expansion and collapse of the cell height.
Thanks to Artem, I figured out I need to call reloadData() on the main thread. This is how I solved that:
func refreshUI() {
dispatch_async(dispatch_get_main_queue(),{
self.stationTableView.reloadData()
});
}
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