Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 623
Maciej Swic Avatar asked Feb 11 '11 11:02

Maciej Swic


People also ask

What does Tableview reloadData do?

reloadData()Reloads the rows and sections of the table view.

Is UITableView scrollable?

Apple's SDK provides two components to help carry out such a task without having to implement everything from scratch: A table view (UITableView) and a collection view (UICollectionView). Table views and collection views are both designed to support displaying sets of data that can be scrolled.

What is UITableView in Swift?

A view that presents data using rows in a single column.


2 Answers

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

like image 117
The Lazy Coder Avatar answered Sep 30 '22 08:09

The Lazy Coder


Call

[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 

instead of

[self.tableview reloadData] 
like image 42
Andrew Avatar answered Sep 30 '22 07:09

Andrew