2013-06-19 26 views
0

我在JSON中獲取圖像url的列表。現在我需要逐個解析圖片網址,並將其轉換爲EGOImage,並在數組中添加該圖片以用該圖片執行動畫。現在,我得到的錯誤是圖像是nil,不能添加到數組。如何將圖像url轉換成EGO圖像並將該圖像添加到NSMutable數組中?

注意事項:圖片網址沒有問題。

我的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]; 
} 
+0

如何獲取網址註冊,添加您的代碼以供參考.... – NANNAV

回答

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