I have 2 main small image buttons say aBtn & bBtn. When i click aBtn / bBtn i Generate 6 image url as default checking the condition that the images are not nil. In the 6 images if some images are empty then i avoid that empty image alone & set the frame accordingly. When i click from aBtn to bBtn, i have the time delay. It is due to checking the 6 url images generate without nil/empty image each time & by setting the frame position accordingly.
This is the code i used to display the images & check the condition from the 6 url images data is not nil if something say 3rd url image is nil it will be avoided. How to overcome the delay to display the images?
NSMutableString *strUrl;
int i;
int j=7;
int k=0;
xorigin=350;
int cou=1;
for( i=1;i<j;i++){
strUrl=[[NSMutableString alloc]init];
UIImageView *imageView= [[UIImageView alloc]init];
[strUrl appendFormat:@"http://commondatastorage.googleapis.com/images2.solestruck.com/%@%@%@%@%@%@%@)-01060%d.jpg",
[[[[shoeDetailDict objectForKey:@"vendorName"] lowercaseString] lowercaseString] stringByReplacingOccurrencesOfString:@" " withString:@"-"],@"-shoes/",[[shoeDetailDict objectForKey:@"vendorName"] stringByReplacingOccurrencesOfString:@" " withString:@"-"],@"-shoes-",[[shoeDetailDict objectForKey:@"productName"] stringByReplacingOccurrencesOfString:@" " withString:@"-"],@"-(",[[prdcolorimgArray objectAtIndex:tagedColor] stringByReplacingOccurrencesOfString:@" " withString:@"-"],i];
NSURL *imageUrl=[[NSURL alloc]initWithString:strUrl];
NSError *error;
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:strUrl] options:NSDataReadingUncached error:&error];
NSLog(@"imageurl colors : %@",strUrl);
if(i==4){
imageView.frame =CGRectMake(25, 0, (self.view.frame.size.width*80)/100,(self.view.frame.size.height*40)/100);
[imageView setImageWithURL:imageUrl];
}
else{
if(data != nil ){
cou++;
imageView.frame =CGRectMake(xorigin, 0, (self.view.frame.size.width*80)/100,(self.view.frame.size.height*40)/100);
[imageView setImageWithURL:imageUrl];
xorigin=xorigin+320;
}
}
imageView.backgroundColor=[UIColor whiteColor];
[productScroll addSubview:imageView];
productScroll.contentSize = CGSizeMake((self.view.frame.size.width)*cou, (self.view.frame.size.height*40)/100);
productScroll.contentOffset=CGPointMake(0, 0);
k++;
}
You are using
dataWithContentsOfURL:that load information synchronously.Try to load all images first and than put them on the scroll view.
Try to use this code: