Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Reload a UITableView While I am Looking at It

When I have a UITableView as part of the visible view controller, how can I reload it so that the data I am looking at changes to the new data. Just calling reload doesn't seem to refresh the data until I scroll it.

like image 295
Genericrich Avatar asked Mar 19 '09 04:03

Genericrich


People also ask

Can I keep the same position in my TableView After reloading the data?

TableView does not reset scroll position. It maintains content offset even after reloadData function is called. So no need to do anything, if you want to keep pixel position.

What does TableView reload data do?

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


2 Answers

Calling the reloadData method refreshes the data as soon as the method is called. It does not wait for the table to be scrolled. Make sure the data source (array or dictionary or wherever you've saved the values) is changed before you call reloadData.

like image 153
lostInTransit Avatar answered Sep 28 '22 22:09

lostInTransit


Are you refreshing the data off the main thread? If so, you need to call the reloadData method using the following method:

- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait

So for a tableView it would be:

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

like image 27
xmr Avatar answered Sep 28 '22 22:09

xmr