Reputation: 33
How to you write an app with multiple pickers and the components that come with it to be specific for each picker. I've seen code but I don't know how to tailor it to be the certain id for that picker while the other picker has different information if that makes sense. Thanks in advance and sorry if its a stupid question. I keep looking at code but I don't understand how to change it to create multiple pickers or how to use a storyboard to do it without writing code just to make it.
Upvotes: 0
Views: 2128
Reputation: 119021
When you look at the delegate / datasource methods for supplying data to picker views or table views:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
You'll see that the first parameter is always a pointer to the view instance that is making the request. So you can always hold properties for your views and use an if statement to decide what to do:
@property (weak, nonatomic) IBOutlet UIPickerView *picker1;
@property (weak, nonatomic) IBOutlet UIPickerView *picker2;
...
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (pickerView == self.picker1) {
// first picker stuff
}
else if (pickerView == self.picker2) {
// second picker stuff
}
...
Upvotes: 3