0
votes

I am calling two webservices and I am displaying both content in one tableview. Since I am calling asynchronously, I would like to load data whichever comes in first and call again when the second service finishes. Response from those services are inserted in their own separate sections and therefore I am saving them in their respective NSarrays.

A -> TO Web Service -> tableView reloadData whenever response arrives

B -> To Web Service -> tableView reloadData whenever response arrives

-(void)UpdateTable{

    if (_firstRequest  || _secondRequest){
        runningRefresh = false;
       [self.tableView reloadData];
        [self removeLoading];
    }

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0){
        return 1;
    }
    else if (section == 1){
        if (!_firstRequest){
            return 1;
        }else{
            NSLog(@"SECTION 1");
            if ([self._collectionsNewGame isKindOfClass:[NSNull class]] || [self._collectionsNewGame count] == 0){
                NSLog(@"0 COUNT");
                return 0;
            }
            NSLog(@"%ld COUNT",[self._collectionsNewGame count]);
            return [self._collectionsNewGame count] + 1;
        }

    }
    else if (section == 2){
        if (!_thirdRequest){
            return 1;
        }else{
            if ([self._collectionsRandom isKindOfClass:[NSNull class]] || [self._collectionsRandom count] == 0){
                return 0;
            }
            return [self._collectionsRandom count] + 1;
        }

    }
    else return 0;
     //count number of row from counting array hear cataGorry is An Array
}

I am just reading in cellrowatindexpath and displaying it.

But, when I do this, there are rows where cells are not showing up and acting weirdly. Any idea how to accomplish this?

1
You need to provide more code. Specifically we need to see the UITableViewDataSource methods that provide the cells. - Dima
Start the name with a lowercase letter and capitalize the first letter of embedded words. Apple Coding Guidelines - Black Sheep

1 Answers

0
votes

Consolidate the response of those services in one single data source lets say an NSArray if what you want is only to add rows to your UITableView instead of using reloadData insert the rows where needed with insertRowsAtIndexPaths: withRowAnimation :. Make sure you have the right validations

Here is the apple reference

Finally use the main queue to perform the UITableview updates

[self performSelectorOnMainThread:@selector(updateTable) 
                   withObject:object 
                waitUntilDone:YES]

By passing YES to waitUntilDone you are blocking the main thread the method has completed.

In the same manner you can use

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self updateTable];
}];  

The difference is that this approach doesn't guarantee when updateTable will be executed. There could be other items in that queue still waiting to execute.