Jon
Jon

Reputation: 4732

How to get image URL out of NSArray?

So I have an NSDictionary with 4 objects in it. Each of these objects then has 2 properties, name and date

I can list out all the data by logging it.

Upvotes: 0

Views: 323

Answers (1)

stack2012
stack2012

Reputation: 2186

You have an NSArray which contains several dictionaries. Firstly,get one dictionary out of the array like this,

NSDictionary *myDict=[myArray objectAtIndex:0];

assuming u have this array under the name myArray. You will get the first dictionary from the array which contains medium,thumbnails,title and another key called url. thumbnails is an array which holds a dict wid a key called url. Now if u want to fetch the outside url key tat is in the myArray just do like this,

NSString *myURL=[myDict valueForKey:@"url"];

This should fetch the url value..Hope this helps.... Happy coding...

NSData *myData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myURL]];
UIImage *myImage = [[UIImage alloc] initWithData:myData;

Now you have ur image. Just create an imageView and set this image to it. To add it to a table, use contentView property like this,

[cell.contentView addSubView:myImageView];

Hope this helps.

Upvotes: 1

Related Questions