Jyoshna
Jyoshna

Reputation: 253

Pass an Url to image view through AFNetworkingLibrary

The project was created with xcode 4.3. I have used AFNetworking Library (non-ARC) in this app.

 NSURL *url = [NSURL URLWithString:urlstring];
 [exhibitPortraitImageView setImageWithURL:url];

Here, when I print a NSLog value, am getting the URL but the imageview is not displayed.

How can I solve this?

Upvotes: 0

Views: 70

Answers (2)

Kanan Vora
Kanan Vora

Reputation: 222

Yes,

I also tried your url, it is working fine.

I loaded it as:

NSURL *correctURL = [NSURL URLWithString:@"http://mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg"];
_imgFromUrl.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:correctURL]];

And the result,

enter image description here

Upvotes: 0

Hemang
Hemang

Reputation: 27050

Your code is fine, problem is with URL.

Your URL, don't have prefix, http://, I added it and the code is same as in quesiton.

 NSString *urlstring = @"http://mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg";
 NSURL *url = [NSURL URLWithString:urlstring];
 [exhibitPortraitImageView setImageWithURL:url];

enter image description here

Here, you've three options to fix this,

1) If URLs are not coming from server (or some where else) you can fix it within the app, see how,

NSString *badUrlString = @"mdb.scicloudsolutions.com:8001/sites/default/files/genesis-book-of-beginnings.jpg";
NSString *goodUrlString = [NSString stringWithFormat:@"http://%@",badUrlString];

2) Or if its coming from server (or some where else) you can ask them to fix this from their side.

3) If its under 2nd option then, ask them if this will always happen (static) then you can also modify this from your side if server side developers not able to fix.

see this for more help, Check string containing URL for "http://"

Upvotes: 1

Related Questions