Redraw UITableView after updating data async

Yonels answer is perfect when your view is currently visible to the user (e.g: User presses a reload button which populates your UITableView.)

However, if your data is loaded asynchronously and your UITableView is not visible during the update (e.g: You add Data to your UITableView in another View and the UITableView is displayed later by userinput), simply override the UITableViewController's viewWillAppear method.

- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.tableView reloadData];
}

The positive effect is that your UITableView only reloads it's data once when the user actually want's to see it, not when new items are added.


I had the similar issue today(Storyboard in iOS 7.0). I was using table View inside a UIViewController.When the view was loaded everything was working fine; all the delegates were getting called.However ; When the underlying dataSource(in my case,Array) was modified; the visible table rows were not getting updated.They were updated; only when I was scrolling the table view.

Tried everything; calling reloadData on Main thread;calling reload in ViewWillAppear; nothing worked.

The issue that I found ; was that I had not made the connection in storyboard; for the table view with the reference Outlet.The dataSource and delegate were set though. I did not think that it could be the issue; as everything was working fine at the first go.

Hope it helps someone.I had some terrible time to find this out.


I guess it wasn't reloaded.

When you scroll the cells to out of screen, then…

tableView: cellForRowAtIndexPath:

…will be called. So it will be reloaded.

I guess UITableView variable is not validated.

If you use UITableView as a main view, you can try this.

[self.view reloadData];

or

[self.tableView reloadData];


You said you're populating content asynchronously but did you invoke the reloadData in the context of the main thread ? (and not via the thread that populates the content)

Objective-C

[yourUITableView performSelectorOnMainThread:@selector(reloadData)
                                  withObject:nil 
                               waitUntilDone:NO];

Swift

dispatch_async(dispatch_get_main_queue(), { self.tableView.reloadData() })

Monotouch

InvokeOnMainThread(() => this.TableView.ReloadData());