2013-04-04 104 views
0

UIImageView沒有得到圖像,並給出null,我也試過用懶惰的代碼,但它仍然給出null。UIImageView不接受圖像並給出Null?如何解決它。

UIImageView *image_view=[[UIImageView alloc]initWithFrame:CGRectMake(10, 2, 50, 58)]; 

    NSString *StrImg=[[NSString alloc]init]; 

    StrImg=[NSString stringWithFormat:@"%@",[[Array_FinalobjectAtIndex:indexPath.row]objectForKey:@"coverphoto"]]; 

    NSLog(@"StrImg value=%@",StrImg); 

[image_view setImageWithURL:[NSURL URLWithString:StrImg] placeholderImage:[UIImage imageNamed:@"star.png"] success:^(UIImage *image) {}failure:^(NSError *error){}]; 
+0

PLZ回答DIS問題... – Coder 2013-04-04 06:22:27

+0

:發佈的NSLog的結果(@ 「StrImg值=%@」,StrImg); – 2013-04-04 06:24:08

+0

http://www.mobiappsolutions.com/nitin/FashionApp/admin/json/images1/515928a26a73c.png – Coder 2013-04-04 06:25:36

回答

1
NSString *str = @"http://www.hdwallpaperspk.com/wp-content/uploads/2013/02/windows-7-wallpaper.jpg"; 

UIImageView *imv=[[UIImageView alloc]initWithFrame:CGRectMake(10, 2, 50, 58)]; 

[self.view addSubview:imv]; 
imv.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:str]]]; 




Try this code. and Please make sure that your sting is valid. means load it in web browser. it must load image in browser. 
+0

如果我傳遞值靜態然後它會給圖像,但如果使用解析它不會給圖像 – Coder 2013-04-04 06:37:57

+0

解析後得到哪個字符串?我認爲你用來加載圖像的字符串是不正確的。意味着該網址字符串中沒有任何圖像。要檢查這一點,請在瀏覽器中加載該字符串。如果它有圖像,那麼它應該在瀏覽器中加載圖像。如果您在瀏覽器中獲取圖像,則只有您可以在imageview中加載圖像。 – Vibhooti 2013-04-04 08:25:15

0

我會建議你使用AsyncImageView通過iCarousel的Nicklockwood -father一個美麗的實現。

https://github.com/nicklockwood/AsyncImageView

它使用起來非常簡單。

#import "AsyncImageView.h" 

並在所有imageViews做到這一點。

[imageView setImage:@"default.png"]; 
    [imageView setImageURL:@"whateverurl/whateverimage.png"]; 

它就像一個魅力,我的代碼是在生產。

0

請檢查您的網址。圖像名稱和圖像路徑。

例如嘗試此鏈接並檢查圖像是否即將到來。

http://thebooksmugglers.com/wp-content/uploads/2012/09/Kat-Zhang.jpeg 

我希望這將工作