I have two PickerViews in my view, how do I set my delegates to identify which one to handle?
Some kind of if()
to validate if the p开发者_JS百科icker that threw the event was the pickerX or pickerY?
Any ideas will be appreciated.
You can have IBOUtlets for the PickerViews like
@property (nonatomic, retain) IBOutlet UIPickerView *firstPickerView;
@property (nonatomic, retain) IBOutlet UIPickerView *secondPickerView;
and then in a delegate method do something like this
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component {
if (pickerView == self.firstPickerView) {
}
else if (pickerView == self.secondPickerView) {
}
}
or you can set tags on the PickerViews in IB and do
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component {
if (pickerView.tag == 0) {
}
else if (pickerView.tag == 1) {
}
}
When any delegate method is called, it also pass the object on which it is called, lets say in this case.
– pickerView:rowHeightForComponent:
You can identify the particular picker by its TAG id. And yah if else will be used.
精彩评论