Crystal
Crystal

Reputation: 29518

Getting values out of an array of NSDictionary

I have an array of NSDictionary. My NSDictionary are essentially small and look like

[NSDictionary dictionaryWithObjectsAndKeys:fname, @"FName", lname, "@LName", img, @"Image", nil];

I have this because I need to store an image with its name, and depending on the sort order, I need to keep the pictures coinciding with the name for my UITableView. So after I resort my array by fname or lname, I'm trying to get the @"Image" out from the dictionary in my cellForRowAtIndexPath method. How do I do that? Thanks.

Upvotes: 1

Views: 1358

Answers (1)

user756245
user756245

Reputation:

Use your index path to retrieve the dictionary in the array :

NSDictionary *d = [myArray objectAtIndex:indexPath.row];

Then get the object for the key @"Image" :

id obj = [d valueForKey:@"Image"];

If you know the type for obj, use it instead of id.

Upvotes: 2

Related Questions