0

I have a UItextField in a UIScrollView. I assigned an inputView (a picker) on my UITextField but it doesn't work. When I click on my textfield, I get the keyboard instead of a picker. When I delete the UIScrollView it works well (I get the picker). Do you have any ideas? Thanks.

Edit (more clear): I have a UItextField in a UIScrollView. I call a method that shows a picker. But the method is never called when my textfield is in a scrollview and I get the keyboard. When I delete the UIScrollView, my method (show picker) is called and I get my picker.

Adrian P
  • 6,479
  • 4
  • 38
  • 55
tchike
  • 154
  • 4
  • 21
  • Try adding the line [textField becomeFirstResponder], this will show the keyboard by default or you could use some other events to trigger this element. – Sandeep Nov 18 '12 at 21:17
  • @insane-36, I click on my textfield to display the picker. Do you have another idea? – tchike Nov 18 '12 at 21:24
  • Then the easy solution would be to set userInteractionEnabled=NO on the textField, that way you can still type into the textField and will not show the keyboard – Sandeep Nov 18 '12 at 21:26
  • @insane-36, now i don't get the keyboard but i don't get neither my picker. when I click on my textfield (touchDown), I call a method that shows my picker. When my textfield is in a scrollview, that method is never called. When i delete the scrollview, it works. – tchike Nov 18 '12 at 21:29
  • Ok then are you having the picker inside the scrollview, if then place it top of the view not inside the scrollview and try triggering. – Sandeep Nov 18 '12 at 21:31
  • @insane-36, my picker is already outside of my scollview. – tchike Nov 18 '12 at 21:34
  • Then is your picker being hidden and you bring it out when the user clicks on textField. Try to log the output and then set the picker unhidden and try to hide on clicking to textField that way you will know what is going on. – Sandeep Nov 18 '12 at 21:38
  • @insane-36, the problem is that when i click on my textfield, i call a method "showpicker". this method is never called when my textfield is in scrollview, so the picker is always hidden. – tchike Nov 18 '12 at 21:42
  • That seems interesting, check to see if your textField is receiving the action if it is then surely enough, the method should be called. – Sandeep Nov 18 '12 at 21:43
  • no it doesn't receive the action when it is in a scrollview. – tchike Nov 18 '12 at 21:45

1 Answers1

2

In case you are already using the textfield delegate, try ...

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField 
{
    [self openCustomPicker:self]; // Call your IBAction method
    return NO;  // Hide both keyboard and blinking cursor.
}

to prevent the UITextField from showing the keyboard.

flashfabrixx
  • 1,183
  • 9
  • 22
  • openCustomPicker is an IBAction. How can I user your method with it? – tchike Nov 18 '12 at 22:26
  • By adding :self behind the method call - see the edited answer. – flashfabrixx Nov 18 '12 at 22:29
  • I get an error: Instance method '-openCustomPicker:' not found (return type default to 'id') – tchike Nov 18 '12 at 22:33
  • What's the name of the method your calling to show the picker like you've said in the question? – flashfabrixx Nov 18 '12 at 22:34
  • I removed self like this [self openCustomPicker]; and my method is called. But my picker isn't shown. Can it be because my textfield is in a scrollview and picker is outside of scrollview? because when i delete my scrollview my picker is shown. – tchike Nov 18 '12 at 22:38
  • Okay, at least the method has been called. It depends on your view and the way your handling the picker. If the picker is outside the scroll view, check if the layer of the picker is higher than the scroll view (last layer = highest layer). – flashfabrixx Nov 18 '12 at 22:46
  • can you explain a bit more about the layers? – tchike Nov 18 '12 at 22:56
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/19728/discussion-between-flashfabrixx-and-tchike) – flashfabrixx Nov 18 '12 at 23:33