如何使用JSON数组填充UIPickerView?

时间:2014-08-02 00:39:15

标签: ios objective-c json uipickerview

我试图用类别的JSON数组填充我的UIPickerView。我需要根据选择器中的选择返回结果。我该怎么办?

1 个答案:

答案 0 :(得分:0)

你必须实现UIPickerViewDatasource& UIPickerViewDelegate协议

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{ 
    return 5;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
    return 1;
}

- (NSString *)pickerView:(UIPickerView *)pickerView 
             titleForRow:(NSInteger)row 
            forComponent:(NSInteger)component
{
    if (component == 0)
         return @"What";
    if (component == 1)
         return @"have";
    if (component == 3)
         return @"you";
    if (component == 4)
         return @"tried";
    return @"?";
}