How do I reload/refresh the UIPickerView (with new data array) based on button press?

You will have to implement the datasource and the delegate.

once you press a button, set an array pointer to the appropriate array.

than call [thePicker reloadAllComponents];

-(IBAction) usButtonPressed:(id)sender{
    self.inputArray = self.usArray;
    [self.thePicker reloadAllComponents];
}

-(IBAction) mexicoButtonPressed:(id)sender{
    self.inputArray = self.mexicoArray;
    [self.thePicker reloadAllComponents];
}

the datasource methods:

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


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [self.inputArray count];
}

the delegate methods:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [self.inputArray objectAtIndex:row];
}

Leave a Comment

tech