0

JSONで画像URLのリストを取得しています。ここで、画像の URL を 1 つずつ解析し、それを変換しEGOImageて配列に追加し、その画像でアニメーションを実行する必要があります。今私が得ているエラーは、画像がnilあり、配列に追加できないということです。

:画像のURLは問題ありません。

私のJSON構造は

{
 "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"
               }
          ]
}

私のコード:

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];
}
4

1 に答える 1

0

EGOImageviews を配列に格納しようとしています。そのためには、最初に適切に初期化する必要があります。これを試してください

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];
}
于 2013-06-19T12:36:07.203 に答える