-1

在我的代码中,我使用 JSONValue 来获取 NSDictionary。

字典看起来像这样:

{
   {ID = 0, NAME = "Patrick"},
   {ID = 1, NAME = "Ted"},
   {ID = 2, NAME = "John"},
   {ID = 3, NAME = "Allen"},
   {ID = 4, NAME = "David"}
}

我想在下面的委托函数中返回对应 ID 的名称:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

最有效的方法是什么?

4

1 回答 1

0

例如:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    // Assuming that you have just one component
    return [jsonDict[row] objectForKey: @(row) ];
}
于 2013-01-22T23:06:49.140 回答