开发者

NSURL code to display an image from a sqlite table

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.u开发者_开发知识库rl];

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

thanks for any help


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]];


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜