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.

4

1 回答 1

1

所以这些是我的答案,我通过反复试验发现的,以及我使用它的方式:

方法:

- (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]];
    }

}

最佳通话地点:

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

我希望这些将帮助其他发现自己处于与我相同的位置的人:)

于 2015-11-22T22:01:54.507 回答