Search code examples
iosobjective-cuipickerview

how to add change event on two different UIpickerView in same storyBoard


i have two different UIpickerView's in same storyboard, and i want to add change event on them and bind different actions with them.

i used below code, it adds event to both the UIpickerView but i want to add to different actions on both of them. But in this case, as both are triggering same action thats why doing the same work.

- (void)pickerView:_picker didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

}

Solution

  • You can set tag to each UIPickerView in storyboard, and now in selection method

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if(pickerView.tag == 0) {
    
    } else if (pickerView.tag == 1) {
    
    }
    }
    

    based on the tag you differentiate the which UIPickerView is selected.