1

I created a UITextField and I set this inputview a pickerview. If I click into the textfield the pickerview is showing, but if I don't want to change the pickerview value, I tried to click on the view to dismiss pickerview, but its not working... I set textfield inputview in viewDidLoad():

picker = [[UIPickerView alloc] init];
picker.dataSource = self;
picker.delegate = self;
self.pickerTF.inputView = picker;

pickerTF is an UITextfield and picker is an UIPickerView.

I tried to use these methods to dismiss pickerview:

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return true;
}
-(BOOL)disablesAutomaticKeyboardDismissal{
return NO;
}

I have already edited .h file:

@interface MyViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate, NetworkManagerDelegate, UITextFieldDelegate>
rounak
  • 9,217
  • 3
  • 42
  • 59
just
  • 1,900
  • 4
  • 25
  • 46

1 Answers1

1

Add a tap gesture recognizer to the textfield's super view and call endEditing: on the super view.

rounak
  • 9,217
  • 3
  • 42
  • 59
  • thanks, i found a solution: http://stackoverflow.com/questions/1456120/hiding-the-keyboard-when-losing-focus-on-a-uitextview – just Jun 23 '15 at 17:32