0

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?

0

3 Answers 3

6

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];
Sign up to request clarification or add additional context in comments.

Comments

0

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

3 Comments

if i have array with some strings and image url then how i can fetch image url without using index number of array. Like myarray={"india",123654,"abc.com/uploads/sarab.jpg",..}
I think you have manage your Array very odd. You can get object from array then from string you can check that, if "www" or ".jpg, .png" exists in string. So it will be like URL and you can bind your Image.
My suggestion is create on NSObject class which has property like Title, Number, ImageUrl (India, 123456, abc.com/uploads.srarb.jpg). And add object of this class into your Array. So that, you will get object by using "Index.Row". Then you can use imageUrl like classObject.ImageUrl. And do the process. Hope you got the answer.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.