Sarabjit Singh
Sarabjit Singh

Reputation: 1824

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 know how to access the image in table view? Is there any example code for help?

Upvotes: 0

Views: 3442

Answers (3)

Mehul Mistri
Mehul Mistri

Reputation: 15147

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..

Upvotes: 0

Nishant B
Nishant B

Reputation: 2897

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

Upvotes: 0

Loquatious
Loquatious

Reputation: 1775

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

Upvotes: 6

Related Questions