In my view i have image view, the data for image view comes form Url, the images are around 1-3 MB . If the user Swipes then i want to load the next image, Every thing works fine if swiped slowly, But when i swiped Fastly I want to Cancel the previous operation and start with new url.
For Ex. if user swipes 4 times if the operations for 2nd and 3rd images is in the middle, i want to cancel those and start downloading 4 th image
But now In the place of 4th image I’m getting first 2nd image follows 3rd and then 4 th image appears.
Here is my sample code
- (void)handleSwipeLeft:(UISwipeGestureRecognizer *)aSwipeGestureRecognizer {
[BackgroundOperation cancelAllOperations]; // To cancel previous one
[self performSelector:@selector(LoadImage) withObject:nil afterDelay:0.1];
}
-(void)LoadImage
{
BackgroundOperation=[[NSOperationQueue alloc]init];
imgvww.image=[UIImage imageNamed:@"loader.png"]; // Place holder till download finishes
[BackgroundOperation addOperationWithBlock:^
{
UIImage *img=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[[self.ItemDetails objectAtIndex:0] objectForKey:@"ImageUrl"]]]]; // Getting data from URL
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
imgvww.image=img; //Adding to image view after completion
}];
}];
}
Thank you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With