URL图像问题iphone

URL图像问题iphone,iphone,ios,objective-c,Iphone,Ios,Objective C,我有两个主要的小图像按钮,分别是aBtn和bBtn。当我单击aBtn/bBtn时,我生成6个图像url作为默认值,检查图像不为零的条件。在这6张图片中,如果一些图片是空的,那么我会避免单独使用空图片,并相应地设置帧。当我从aBtn单击到bBtn时,我有时间延迟。这是因为每次都要检查生成的6个url图像,而不使用nil/empty图像&通过相应地设置帧位置 这是我用来显示图像的代码&检查6个url图像数据的条件是否为nil如果第3个url图像为nil,则可以避免。如何克服显示图像的延迟 N

我有两个主要的小图像按钮,分别是aBtnbBtn。当我单击aBtn/bBtn时,我生成6个图像url作为默认值,检查图像不为零的条件。在这6张图片中,如果一些图片是空的,那么我会避免单独使用空图片,并相应地设置帧。当我从aBtn单击到bBtn时,我有时间延迟。这是因为每次都要检查生成的6个url图像,而不使用nil/empty图像&通过相应地设置帧位置

这是我用来显示图像的代码&检查6个url图像数据的条件是否为nil如果第3个url图像为nil,则可以避免。如何克服显示图像的延迟

    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++;
    }
NSMutableString*strUrl;
int i;
int j=7;
int k=0;
xorigin=350;
int-cou=1;

对于(i=1;i您正在使用
dataWithContentsOfURL:
同步加载信息

尝试先加载所有图像,然后将它们放在滚动视图上

请尝试使用以下代码:

- (void) prepareImages {
    dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
        NSMutableArray * imagesArray = [NSMutableArray array];
        // Load all images here
        [self imagesLoaded:imagesArray]
    });
}
- (void) imagesLoaded:(NSArray*) images {
     dispatch_async(dispatch_get_main_queue(), ^{
        //Display images here
    });
}

我猜延迟是从网站下载图像所需的时间?尝试使用NSThread detachNewThreadSelector:否延迟是因为如果数据不是nil,则检查图像@trojanfoe@Saha_pre,setImageWithURL:
从哪里来?@vikingosegundo:I使用SDWebImage UIImageView+WebCache.h(setImageWithURL:)单独显示图像。