views:

35

answers:

2

Ii'm using this NSURL code to display an image. what I want to do is to insert a url from my database table in place of the static url shown in the code below:

Does anyone know how I should proceed?

NSURL *url = [NSURL URLWithString:@"http://www.nyapplecountry.com/images/photosvarieties/redrome04.jpg"];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]]; 
[self.view addSubview:[[UIImageView alloc] initWithImage:image]];
[self.containerView addSubview:self.mainView];

I was thinking of something like:

NSString *urlAddress = [NSString stringWithFormat:@"%@", place.url];

where place.url is coming from my db table. I'm missing something though, not sure what.

thanks for any help

A: 

You can't do it that way. You have to read image from data base and initialize UIImage with that data.

eviltrue
+1  A: 

Is place.url a NSString object and the full URL to the image? Then it would be as simple as

NSURL *url = [NSURL URLWithString:place.url]; 
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
bosmacs
place.url is the full URL to the image. that works perfectly. thanks so much.
hanumanDev