开发者

Image downloaded with NSURLConnection displays correctly on simulator, not at all on iPod

开发者 https://www.devze.com 2023-03-19 06:56 出处:网络
I\'m downloading an image (.jpg) from a webserver and then displaying it full screen in an UIImageView.In the simulator the image is displayed correctly, but when I loaded the 开发者_JAVA技巧applicati

I'm downloading an image (.jpg) from a webserver and then displaying it full screen in an UIImageView. In the simulator the image is displayed correctly, but when I loaded the 开发者_JAVA技巧application on an iPod (iOS 4.3.2) I get a blank white page. I get the NSData for the image back from the NSURLConnection and then set it in viewDidLoad with this code:

UIImage *map = [UIImage imageWithData:theData];
mapView.image = map;

My mapView is setup without an image in a UIView in Interface Builder. I also have a toolbar that isn't showing on the device, like the UIImageView it shows up as expected on the simulator. Has anyone seen similar behavior?


Would you try with this code?

 - (void)viewDidLoad {
       UIImage *img = [[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://xxxxxxx/xxxx.jpg"]]] retain];
       if (img != nil) {
            mapView.image = img;
            [img release];
    }
    [super viewDidLoad];
 }

It is possibly not ok for you, but just for a try...


I'm not sure what the problem was but I abandoned the Interface Builder and added the ImageView by hand and it now shows up correctly.


Try this with ARC:

NSURL *url = [NSURL URLWithString: @"http://clasificados.eluniversal.com/imagenes/inmuebles/home/home_inmuebles.jpg"];

UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:url]];
if (img != nil) {
    mapView.image = img;
    img = nil;
}
0

精彩评论

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