Possible Duplicate:
Get notified when UITableView has finished asking for data?
is it possible to get notification when tableview finish to reload its data after reloadData method? Or is it possible to wait till tableview finish reloading?
Thanks
Possible Duplicate:
Get notified when UITableView has finished asking for data?
is it possible to get notification when tableview finish to reload its data after reloadData method? Or is it possible to wait till tableview finish reloading?
Thanks
There is a very simple solution is to check if you are in the last iteration of the delegate
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
after last iteration finished in 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
Lets put a completion block in. Who doesn't love 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
Usage:
[self.tableView reloadDataWithCompletion:^{
//do your stuff here
}];
EDIT:
Note that the above is only half the solution. The number of sections and rows and the row heights are updated synchronously on the main thread, so using the above code, the completion would call back when some of the UI part was done. But the data loading from the datasource is asynchronous - so really this answer isn't quite what @Michal wanted.