1

I know its very basic question, but i'm facing a strange behaviour with UIPickerView. Here is my scanario - I'm using UIPickerView in my app. my problem is that when i click on a row didSelectRow method is not called, however when i scroll rows of picker then its working. more specific assume that first row on picker is currently selected and if i click on 4th row then didSelectRow method not fired. What am i missing?

UPDATE: if i comment this code from viewDidLoad method then all works fine-

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]
                                   initWithTarget:self
                                   action:@selector(dismissKeyboard)];

    [self.view addGestureRecognizer:tap];

and

-(void)dismissKeyboard {
    [numberTextField resignFirstResponder];
    [nameTextField resignFirstResponder];
    [cityTextField resignFirstResponder];
    [addressTextField resignFirstResponder];
    [zipTextField resignFirstResponder];
}
Blios
  • 719
  • 1
  • 16
  • 30
  • possible duplicate of [UIPickerView - 1st row selection does not call didSelectRow](http://stackoverflow.com/questions/788357/uipickerview-1st-row-selection-does-not-call-didselectrow) – trojanfoe Nov 08 '12 at 12:34
  • @trojanfoe no its not duplicate of that question, i'm not interested on close picker view by tapping on selected row. Read my question again. – Blios Nov 08 '12 at 12:44
  • So if you leave the tap recognizer uncommented does the dismissKeyboard action fire when you touch a row in the Picker? Sounds like the tap recognizer is eating the touch events – Mike Nov 08 '12 at 13:20
  • @monkybonk05 yes if i leave the tap recognizer uncommented the dismissKeyboard action fired. – Blios Nov 08 '12 at 13:34

2 Answers2

1

I'm assuming you're trying to use the tap gesture recognizer to dismiss the keyboard if they click anywhere in the view. The problem this is causing is now your UIPicker is not getting touch events passed to it. I have two ideas for possible solutions.

1) Inside the method:

  • (CGPoint)locationOfTouch:(NSUInteger)touchIndex inView:(UIView *)view

test the location and/or the view to determine if the picker was touched or not, and then forward the event.

2) Instead of adding the tap recognizer to the entire view, add an invisible subview to the likely tap area to close the keyboard that won't overlap the picker.

Mike
  • 2,399
  • 1
  • 20
  • 26
0

Did you try adding Gesture recognizer to other parts of self.view than the pickerview?

Paramasivan Samuttiram
  • 3,728
  • 1
  • 24
  • 28