for UIPickerView to work correctly, you must specify the number of components (columns) and the number of rows for each component each time you reload: as mentioned, use [myPickerView reloadAllComponents];to reload the view after filling the array, but you MUST implement these things after declaring the class of the view controller as <UIPickerViewDelegate>associate the collector with the owner of the file as a delegate, and then:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if (myLoadedArray!=nil) {
return [myLoadedArray count];
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (myLoadedArray!=nil) {
return [myLoadedArray objectAtIndex:row];
}
return @"";
}
source
share