Question

I am getting the list of image url in JSON. Now I need to parse the image url one by one and convert it into EGOImage and add that in an array for performing animations with that images. Now the error what I am getting is the image is nil and cannot be added to array.

Note: There is no problem with the image url.

My JSON structure is

{
 "images":[
               {
                 "url":"https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcRQmkaIO86rYB-DctBruyv4lFTEM-v_pGG9k5i0lrAr2Elzibvuiw"
               },
               {
                  "url":"https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQGh1nRGgnbUZXgKLMKGdeT320PGttnLmbN4R-DxmckQpjVDhHS"
               }
          ]
}

My code:

NSMutableArray*arrForImageURL = [dic objectForKey:@"images"];
arrForUniqueWorderImages=[[NSMutableArray alloc]init];
for (NSDictionary*dictForImg in arrForImageURL)
{
   NSString*stringForImageURL=[dictForImg objectForKey:@"url"];
   imgView.imageURL=[NSURL URLWithString:stringForImageURL];
   [arrForUniqueWorderImages addObject:(EGOImageView*)imgView.image];
}

No correct solution

OTHER TIPS

You are trying to store EGOImageviews in the array,For that you have to initialize it first properly .Try this

NSMutableArray*arrForImageURL = [dic objectForKey:@"images"];
arrForUniqueWorderImages=[[NSMutableArray alloc]init];
for (NSDictionary*dictForImg in arrForImageURL)
{
   EGOImageView *imageView = [[EGOImageView alloc] init];

   imageView.contentMode=UIViewContentModeScaleAspectFit;
   NSString*urlString=[dictForImg objectForKey:@"url"];
   NSURL *imageUrl=[NSURL URLWithString:urlString];
   imageView.imageURL =imageUrl;
   imageView.frame=CGRectMake(0,0,320,300);
   [arrForUniqueWorderImages addObject:imageView];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top