0

Aster finding myself in the situation of wanting to disable a UIPickerView component and not finding any answers that uses the default functionality but tries to go around it by using labels or multiple UIPickerViews, I start poking around the UIPickerView structure in order to find a more direct approach to solve the problem by using the OS already present functionality.

Laur Stefan
  • 1,519
  • 5
  • 23
  • 50

1 Answers1

1

So these is my answer, what I found by trial and error, and the way that I am using it:

The method:

- (void)dissableUIPickerViewComponent:(int)componentToDissable forPickerView:(UIPickerView *)pickerView{

    NSArray *pickerViews = [[NSArray alloc] initWithArray:[pickerView subviews]];
    UIView *mainSubview;
    for (int count = 0; count < pickerViews.count; count++) {
        UIView *temp = [pickerViews objectAtIndex:count];
        if (temp.frame.size.height > 100) {
            mainSubview = temp;
        }

    }

    NSArray *componentSubview = [mainSubview subviews];
    while ([[[[componentSubview objectAtIndex:componentToDissable] subviews] firstObject] superview].gestureRecognizers.count) {
        [[[[[componentSubview objectAtIndex:componentToDissable]subviews]firstObject]superview] removeGestureRecognizer:[[[[[componentSubview objectAtIndex:componentToDissable]subviews]firstObject]superview].gestureRecognizers objectAtIndex:0]];
    }

}

Best place to call:

- (void)viewDidAppear:(BOOL)animated{
   [self dissableUIPickerViewComponent:0 myPickerView];
}

I hope these will help others that found themself in the same position that I did :)

Laur Stefan
  • 1,519
  • 5
  • 23
  • 50
  • 1
    Mucking around in the view hierarchy of system controls is a bad idea, and likely to break with future system update. – Duncan C Nov 22 '15 at 22:13