开发者

UIImageView from a url is not appearing

开发者 https://www.devze.com 2023-01-23 09:05 出处:网络
I have declared an UIImageView as an IBOutlet and I am setting the image of the imageView as follows in viewDidLoad method

I have declared an UIImageView as an IBOutlet and I am setting the image of the imageView as follows in viewDidLoad method

imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:
    [NSURL URLWithString: [productProperties objectForKey:@"image"]]]]; 

But this image doesn't show up at all.

productProperties is开发者_JS百科 a NSDictionary which stores the url for the key "image"

I even tried storing the image locally and then setting it up like below

imageView.image = [UIImage imageNamed:@"icons_browse.png"];

But that also doesn't work.


Try removing the line of code and setting the "default" image in IB.

I know this is not a fix - but I am curious to see of there is some other reason why it is not visible - like it's set as hidden, has 0% alpha, is obscured by something else, etc.

The code - especially the second thing you tried (assuming the file is actually in your bundle and named properly) is very boilerplate and should work..

The other thing to do is to check the value being returned by [UIImage imageNamed] - and make sure it's not nil - meaning there is actually some problem loading the file. (Wrong file name, file not in bundle, etc.)


Sorry guys, it is my mistake, I am providing the wrong value for the NSURL. got it fixed

0

精彩评论

暂无评论...
验证码 换一张
取 消