开发者

how to fetch url from array and show image on table view

Thanks in advance. I fetch image url in array.

myarray = { "http://www.abc.com/uploads/sarab.jpg", .... };

And now i dont kno开发者_StackOverflow社区w how to access the image in table view? Is there any example code for help?


Put this code in cellForRowAtindexPath then it will work fine :

NSData *imageData= [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[myarray objectAtIndex:indexPath.row]]];
cell.imageView.image=[UIImage imageWithData:imageData];


Below way, you can achieve this:

NSString *strImageUrl = [myarray objectAtIndex:indexpath.row];
NSURL *url = [NSURL URLWithString: strImageUrl];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]]; 
UIImageView *displayimage = [[UIImageView alloc] init];
[displayimage setImage:image];

Let me know in case of any difficulty.

Cheers


You should have to do this,

for fetching URL from Array Put this code in CellForRowAtIndexPath, this will help you..

NSString *str = [YOUR_ARR objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:str];

First of all convert URL to NSData then assign then data to your Image..

NSData *imgData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imgData];

and after that

cell.imageView.image = image;

Happy coding..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜