Reputation: 23
I have three different buttons. When I click those buttons, it shows a picker view. I am using the same picker view each time, but the rows in the picker view should be different depending on which button was pressed.
How do I make the picker view display the rows I want, depending on which button was pressed?
Upvotes: 0
Views: 257
Reputation: 2083
I assume you use the UIPickerView and the delegate for that pickerView is the same viewController as where you buttons are.
I would create 4 arrays, 3 for each button with the values to show in the picker and 1 array that is used by – pickerView:titleForRow:forComponent:
NSArray *pickerData;
NSArray *button1Data;
NSArray *button2Data;
NSArray *button3Data;
Then in the IBActions of the buttons (or you set the target and selector in code)
- (IBAction)button1Action:(id)sender {
[pickerData release];
pickerData = [button1Data retain];
}
- (IBAction)button2Action:(id)sender {
[pickerData release];
pickerData = [button2Data retain];
}
etc...
And in – pickerView:titleForRow:forComponent:
you use pickerData to display your values
I hope this makes sence
Upvotes: 1