sasa sasa
sasa sasa

Reputation: 55

Retrieve `valueForKey` as string

I have a NSArray that contain three keys with their corresponding values… When I retrieve the value for a key with the method valueForKey: I get this on a NSLog():

2012-05-18 21:59:52.176 ScrollApp[21443:f803] value for key is(
    "Image 4"
)

which is exactly the value I set on the plist.

But if I assign this values to the text of the label the compiler complain with unrecognized selector sent to instance.

I know I will have to retrieve the returning value of the array as a string and pass it to the label.

The question is how?

This is the code:

NSArray *imgList = [[NSArray alloc]initWithContentsOfFile:path];
NSArray *imgName = [[NSArray alloc] initWithObjects:[imgList objectAtIndex:3], nil];

NSLog(@"%@", [imgName valueForKey:@"Details"]);

NSString *currentPic = [imgName valueForKey:@"Details"];

subPanel.small_panel_Detail_Lbl.text =  currentPic;

Upvotes: 0

Views: 1917

Answers (1)

rdelmar
rdelmar

Reputation: 104082

valueForKey when sent to an array returns an array of all the values with that key in the array -- it may only be one value, but it will be in an array. If you log [currentPic class], I'm guessing that it will be an array, so you need to send objectAtIndex to it to get a single string

Upvotes: 2

Related Questions