2

I've got the following code that loads on an UIImageView the image that I want from the internet:

NSString* mapURL = @"http://mydomain.com/image-320x480.png";
NSData* imageData = [[NSData alloc]initWithContentsOfURL:url];

 UIImage* image = [[UIImage alloc] initWithData:imageData];
 [marcaBackground setImage:image];
 [imageData release];
 [image release];

I'd like instead of hardcoding the URL of the image, to load a string of another URL and then load that image on the UIImageView.

My URL returns just another URL in text format.

For example: http://mydomain.com/url returns http://mydomain.com/image-320x480.png

How could I accomplish this task?

4

1 に答える 1

3

使用する:

NSData *imageData = 
   [[NSData alloc] initWithContentsOfUrl:
       [NSString 
           stringWithContentsOfUrl: 
             [NSURL URLWithString:@"http://mydomain.com"]
           encoding: NSUTF8StringEncoding
           error: nil
       ]
   ];

次に、すでに行っていたように続行します。

UIImage* image = [[UIImage alloc] initWithData:imageData];
[marcaBackground setImage:image];
[imageData release];
[image release];
于 2010-10-01T16:11:07.630 に答える