Wait for UITableView to restart.

Possible duplicate:
Get notified when UITableView has finished requesting data?

Can I get a notification when a tableview ends to reload its data after reloadData? Or can I wait for the table to reload?

thanks

+4
source share
2 answers

There is a very simple solution - check if you are in the last delegate iteration

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

after the last iteration at the end add your code there

 -(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if([indexPath row] == lastRow){ any code you want } } 

thanks

+2
source

Includes a completion block. Who doesn't like a block?

 @interface DUTableView : UITableView - (void) reloadDataWithCompletion:( void (^) (void) )completionBlock; @end 

and...

 #import "DUTableView.h" @implementation DUTableView - (void) reloadDataWithCompletion:( void (^) (void) )completionBlock { [super reloadData]; if(completionBlock) { completionBlock(); } } @end 

Using:

 [self.tableView reloadDataWithCompletion:^{ //do your stuff here }]; 

EDIT:

Please note that the top half is the solution. The number of sections and rows and row heights are synchronously updated in the main thread, so using the above code, the termination will call back when part of the user interface has been completed. But loading data from a data source is asynchronous - so really this answer is not quite what @Michal wanted.

+1
source

All Articles