0

My functionality is to open picker on click of textField. My textfield is inside scrollview is shown in below image.

enter image description here

I want to disable userinteraction of scrollview when picker opens. Following is my code.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{

    [self.picker removeFromSuperview];
    [self.toolBar removeFromSuperview];
    textField.inputView = self.picker;
    textField.inputAccessoryView = self.toolBar;
    self.scrollview.userInterationEnabled = NO;
    return YES;
}

When I comment the userInteractionEnabled code. Picker is opening perfectly. But when I uncomment code picker is not opened.

Also I gave some delay for this code. so after dalay my picker is hidden again.

iPhone
  • 4,092
  • 3
  • 34
  • 58
  • maybe it is because yopur textFieled is child of the scroll view, maybe try to use isScrollEnabled on the scroll view. Also you can try to display the picker in the root view insted as inputView of the textField. Info about userInteractionEnabled https://stackoverflow.com/questions/10880868/on-ios-if-a-superviews-userinteractionenabled-is-no-then-all-subviews-are-dis – m1sh0 Oct 16 '18 at 11:03
  • did you fix the problem?? – m1sh0 Oct 19 '18 at 08:25

2 Answers2

1

The problem here is that userInteractionEnabled is inhereted from the scrollView to the textField. And as it is explained here

A UITextField will also refuse to become first responder if its userInteractionEnabled property is NO as I just discovered. I had to explicitly re-enable user interaction on the text field before it would accept first responder status.

And it can not show the inputView of the textField.

You shou ensure that your textField userInteracationEnables is true or to move the pickerView outside of the textField.inputView.

m1sh0
  • 2,236
  • 1
  • 16
  • 21
0

You can use this cool customizable control for having picker as an inputView on textfield.

Or this one if you want to disable the interaction to background view while picker is open.

Mayur Shrivas
  • 199
  • 1
  • 13