Call function only after reloadData has finished

I have a tableView and need to perform a function once the tableView has been reloaded. How do I know if reloadData has finished? Lets say I have methodA that populates the tableView, and once [tableView1 reloadData] has been completed, I want to call methodB. Can anyone help me with this? I've been searching for hours... Thank you!

- (void) methodA

    NSString *URLa = [NSString stringWithFormat:@"
    v1=%@&v2=%@&v3=%@",v1, v2, v3];

    NSURL *url = [NSURL URLa];

    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    (void) [[NSURLConnection alloc] initWithRequest:request delegate:self];

    [tableView1 reloadData];



The problem is that you call reloadData immediately after starting the URL request. That does not make sense because the request has not been completed at that point.

The correct way would be to call reloadData and methodB in connectionDidFinishLoading, after you have updated your data source with the response from the URL request. At that point you know if the number of rows is zero or not, and there is no need to wait for the table view update to complete.

You can add a method/category on UITableView or even subclass UITableView:

-(void)reloadDataAndWait:(void(^)(void))waitBlock {
    [self reloadData];//if subclassed then super. else use [self.tableView

And you need to use it as

[self.tableView reloadDataAndWait:^{
    //call the required method here                                            

Once I get updated data from server for my table.

I use following code snip to Hide progress bar when table reload gets complete.

[UIView animateWithDuration:0 animations:^{
            [your_table_view reloadData];
        } completion:^(BOOL finished)
            //Table reload completed TODO here
            //Hide progress bar etc.

Need Your Help

Generating Code in an MSBuild task

c# msbuild code-generation compilation itaskitem

I am creating an MSBuild task that will generate one or more files, I have a Task with an [output] property that is of type ITaskItem[]. My question is, do I need to implement that interface myself...

iOS, upload file with multipartform-data

ios http multipartform-data

I would like to upload file to HTTP server. I do it like that right now: