[tableView reloadData]; doesn't work until I scroll the tableView

Maciej Swic picture Maciej Swic · Feb 11, 2011 · Viewed 12.6k times · Source

I have a simple app that downloads search results in XML when the user types in a UISearchBar. The download+parsing is threaded and once done it fires an NSNotification to tell the ViewController with the table view to [tableView reloadData];

Here is the code that receives the notification fired once results are in:

- (void)receivedResults:(id)notification {
    results = [notification object];
    DLog(@"Received %i results",[results count]);
    [[self tableView] reloadData];
}

I get the log output "Received 4 results", but the table view doesn't reload the data until I scroll/drag it a couple pixels. I am using the built-in UITableViewCellStyleSubtitle cell style and im not changing the height or ding anything fancy with the table view.

What am I doing wrong?

Answer

The Lazy Coder picture The Lazy Coder · Aug 16, 2012

I was able to get the same thing to work. But the issue was that the reload data needed to be called on main thread.

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableView reloadData];
});

I think this is more practical than the performSelectorOnMainThread option