XCode iPhone Programming: Loading a jpg into a UIImageView from URL

Posted by Antonio Murgia on Stack Overflow See other posts from Stack Overflow or by Antonio Murgia
Published on 2010-03-24T18:00:52Z Indexed on 2010/03/24 18:03 UTC
Read the original article Hit count: 806

Filed under:
|
|
|
|

My app has to load an image from a http server and displaying it into an UIImageView
How can i do that??
I tried this:
NSString *temp = [NSString alloc];
[temp stringwithString:@"http://192.168.1.2x0/pic/LC.jpg"]
temp=[(NSString *)CFURLCreateStringByAddingPercentEscapes(
nil,
(CFStringRef)temp,
NULL,
NULL,
kCFStringEncodingUTF8)
autorelease];

NSData *dato = [NSData alloc];
dato=[NSData dataWithContentsOfURL:[NSURL URLWithString:temp]];
pic = [pic initWithImage:[UIImage imageWithData:dato]];

This code is in viewdidload of the view but nothing is displayed! The server is working because i can load xml files from it. but i can't display that image!
I need to load the image programmatically because it has to change depending on the parameter passed! Thank you in advance. Antonio

© Stack Overflow or respective owner

Related posts about xcode

Related posts about iphone