user616076
user616076

Reputation: 4001

How do I use multiple pickers?

My app collects various types of information and sends it off to our server. Some of the questions are of fixed type so I need to use Pickers. When I've used pickers before they are initialised when the app starts with the array of selections. I had thought I would use different pickers through various subViews. Would it be better to use just one Picker and then reset the array used dynamically. If so how do I do this?

Upvotes: 0

Views: 460

Answers (2)

Rakesh Bhatt
Rakesh Bhatt

Reputation: 4606

Note that each method of both the datasource and the delegate protocols contain a UIPickerView * parameter, for instance:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

You need to use it to distinguish between your two instances, as follows:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
if([pickerView isEqual: pickerOne]{
  // return the appropriate number of components, for instance
     return 3;
}

if([pickerView isEqual: pickerTwo]{
  // return the appropriate number of components, for instance
     return 4;
}
}

Upvotes: 1

Devang
Devang

Reputation: 11338

Give the two different tags. And compare tag for loading your array.

Upvotes: 0

Related Questions