i have a UITableView which shows (doctor image , doctor Name)
In the cellForRowAtIndexPath function iam fetching the images as follow:
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse * response,
NSData * data,
NSError * error) {
if (!error){
dispatch_async(dispatch_get_main_queue(), ^{
updateCell.DRImage.image = [[UIImage alloc] initWithData:data];
}];
The Problem is: when i'm scrolling down fast , the images start loading , and almost 100 images being loaded , then when i click on row to show the doctor details , i can't get the data from the server until all the images finish loading (until all async requests finish).
i'm using the following code to get the doctor details:
SoapCall *Obj = [[SoapCall alloc] init];
NSString* Url=[[NSString alloc] initWithFormat:@"%@/doctorsDetails.php?i=%@" , ServerUrl ,DoctorDataFromTableView.Doctor_ID];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
[Obj CallUrl:Url OnCompletion:^(NSMutableArray * Results , NSError * Error){
dispatch_async(dispatch_get_main_queue(), ^{
Nviews.text =[[Results objectAtIndex:0] objectForKey:@"numViews"];
NComments.text =[[Results objectAtIndex:0] objectForKey:@"totComments"];
});
}];
Note: SoapCall is a custom class i made to make an Async request to the server
my question is : Is there is any way to cancel loading the images???
Or can i load the Doctor details in different thread ???