2013-04-04 64 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 

我希望这将工作

相关问题