2014-03-26 41 views
0

如何使用缓存将图像显示到UICollectionView并将大图像显示到另一个 在UICollectionView didSelect上查看。上的CollectionView这里既有大和拇指像这样下次查看大图不blank.using EMAsyncImageView将图像加载到缓存中并显示到UIImageView中

NSURL *url = [NSURL URLWithString:@"http://leewayinfotech.com/mobile/girlwallpaper/api.php?category=abstract&device=i5&hits=all"]; 
NSURLRequest *req = [NSURLRequest requestWithURL:url]; 
[NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { 
    NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
    //NSLog(@"Response String=%@",responseString); 
    NSError *jsonError; 
    NSData *trimmedData = [responseString dataUsingEncoding:NSUTF8StringEncoding]; 
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:trimmedData options:NSJSONReadingAllowFragments error:&jsonError]; 

    if (jsonError) { 
     NSLog(@"JSON parse error: %@", jsonError); 
     return; 
    } 

    obj_Array=[[NSMutableArray alloc] init]; 
    obj_Array=[json objectForKey:@"wallpaper"]; 

    //NSMutableArray *tmp = [NSMutableArray arrayWithCapacity:[obj_Array count]]; 
    imgPage.thumb_img_Array=[NSMutableArray arrayWithCapacity:[obj_Array count]]; 
    imgPage.device_img_Array=[NSMutableArray arrayWithCapacity:[obj_Array count]]; 
    imgPage.imgNo_Array=[NSMutableArray arrayWithCapacity:[obj_Array count]]; 

    for (int i=0; i<[obj_Array count]; i++) { 
     ImgClass *obj_Class=[[ImgClass alloc] init]; 
     obj_Class.main_id=[[[obj_Array objectAtIndex:i] valueForKey:@"id"] integerValue]; 

     [obj_Class.thumb_img_Array addObject:[[[obj_Array objectAtIndex:i] objectForKey:@"images"] objectForKey:@"image_thumb"]]; 
     [obj_Class.device_img_Array addObject:[[[obj_Array objectAtIndex:i] objectForKey:@"images"] objectForKey:@"image2"]]; 
     NSLog(@"Thumb-->%@\n\nDevice-->%@",[obj_Class.thumb_img_Array description],[obj_Class.device_img_Array description]); 
     [appDelg.my_Array addObject:obj_Class]; 
    } 
+0

。把一些代码写到设置图像上。 – Vidhyanand

回答

0

您可以使用SDWebImage。使用SDWebImage,您可以使用imageURLString像下面一样使用CacheType设置图像。

[yourImgView setImageWithURL:[NSURL URLWithString:imageURLString] 
         placeholderImage:[UIImage imageNamed:@"noimage.png"] 
           completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) 
     { 
      if (!error && image) 
      { 

      } 
     }]; 

@ Montu..Are您使用SDWebImage加载图像希望它会帮助你..

相关问题