我从JSON获得数据。像这样
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
al=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSLog(@"String String %@",al);
for (array in al) {
NSLog(@"array is array %@",array);
}
}
PickerView方法:-
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return array.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return array[row];
}
我尝试过这种方法,但它显示的PickerView为空。所以请给我任何想法。
我的Json这样:
[[1,"Hyd"],[2,"viz"]]
类似这样的方法应该起作用:
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return [((NSArray *)array[0]) count]; // check for boundary conditions
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return array.count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return array[row][1]; // title exists at 1 index of each 2d array.
}