I am doing following thing to load my image from server. But problem is that imageview is showing up 5-7 seconds later when alertview is closing.
how to solve this ?
- (void)showFullImage :(id) sender
{
// for loading view
self.loading_alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"LOADING",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[self.loading_alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(125, 65, 30, 30)];
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
//indicator.center = CGPointMake(loading_alert.bounds.size.width / 2, loading_alert.bounds.size.height - 50);
[indicator startAnimating];
[self.loading_alert addSubview:indicator];
self.image_url = [self.question_set valueForKey:@"image_url"];
//--------Asyncronously fetch image----------------------------------------
NSURL *URL = [NSURL URLWithString:image_url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL cachePolicy:NSURLCacheStorageAllowedInMemoryOnly
timeoutInterval:60.0];
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error){
NSLog(@"1",nil);
imgView= [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480) ];
UIImage* queImage = [UIImage imageWithData:data];
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,42,320,420)];
iv.image = queImage;
[imgView addSubview:iv];
[self.view addSubview:imgView];
//dismiss alert view on main thread
dispatch_async(dispatch_get_main_queue(), ^(void) {
// dismiss alert view...
NSLog(@"2",nil);
[self.loading_alert dismissWithClickedButtonIndex:0 animated:YES];
});
}];
}
Help will be appreciated.