Search code examples
iphoneobjective-cnsdictionaryuipickerview

Objective c Setting picker value from NSDictionary


Another, probably simple problem that, having tried for a good few hours now I'm pretty stumped on. Simply, I want to set the value of a picker from a NSDictionary, I don't mind! Every way I have tried pretty much gives me the warning Passing argument 1 of selectRow inComponent animated' makes integer from pointer witout a cast. Which makes sense, though I seem to be failing miserable at fixing it! Any help would be greatly appreciated! Snippet of code below...

NSArray *myValue = [parsedJson objectForKey:@"Details"];
NSEnumerator *myEnumerator = [myValue objectEnumerator];
NSDictionary* myItem;

int i = 0;
while (myItem = (NSDictionary*)[myEnumerator nextObject])
{
    [myPickerView selectRow:[myItem objectForKey:@"Value"] inComponent:i animated:YES];
    i++;
}

Solution

  • Assuming your value responds to intValue message (e.g. number is stored in NSNumber or NSString) then the following should work:

    [myPickerView selectRow:[[myItem objectForKey:@"Value"] intValue]
                inComponent:i animated:YES];