I'm trying to populate a UIPickerView with JSON data that is parsed into an NSArray.
The console shows that the JSON is parsing properly but the UIPickerView is remaining empty.
Here's my code:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//set number of rows
return self.terrainJsonArray.count;
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//set item per row
return [self.terrainJsonArray objectAtIndex:row];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Parse JSON
NSString *terrainString = [NSString stringWithFormat:@"http://terrainracing.com/ios/events_json.php"];
NSURL *terrainUrl = [NSURL URLWithString:terrainString];
NSData *terrainData = [NSData dataWithContentsOfURL:terrainUrl];
NSError *error;
NSArray *terrainJsonArray = [NSJSONSerialization JSONObjectWithData:terrainData options:kNilOptions error:&error];
NSLog(@"%@", terrainJsonArray);
}