How to dismiss a UIPicker that is connected to a UITextField


I have a UITextField, and when pushed a UIPickerView comes up to choose a value. How do I get the UIPickerView to dismiss once a value is chosen. Someone in another thread told me to resignFirstResponder the textfield, but my code isn't working. Any ideas? NOTE: I have two text fields and UI Pickers, that's why I have the 'if' 'else' statement.

- (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == self.ageTextField) { [ageTextField resignFirstResponder]; [agePickerView removeFromSuperview]; return YES; } else { [relationshipTextField resignFirstResponder]; [relationshipPickerView removeFromSuperview]; return YES; } }


Try the following code which may solve your problem.

- (BOOL)textFieldShouldReturn:(UITextField *)textField { if (textField == self.ageTextField) { [ageTextField resignFirstResponder]; } else { [relationshipTextField resignFirstResponder]; } [pickerView removeFromSuperview]; return YES; }

or resign your keyboard on following method of UIPickerView.

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component


Please try resigning the UITextField in UIPickerViewDelegate method as follows.

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { [self.ageTextField resignFirstResponder]; pickerView.hidden = YES; //Show the pickerview again when you neeed it }


Implement the UIPickerViewDelegate protocol and implement the following method:

- (void) pickerView: (UIPickerView*) pickerView didSelectRow: (NSInteger) row inComponent: (NSInteger) component { [self.ageTextField resignFirstResponder]; }


  • Setting JLabels in rows and placing the equivalent JTextField right next to it
  • Sorting data in Foreign key drop down lightswitch
  • minDate: 0, not working in datepicker
  • minDate: 0, not working in datepicker
  • Java Arabic (Hirji) Calendar
  • UITextField — observe changes to selectedTextRange?
  • for loop iteration in django
  • php: best way to validate POST
  • Client server multithread Socket
  • How to find MongoDB field name at arbitrary depth
  • Iterating over a container bidirectionally
  • Insert Statement
  • Escaping single quotes in JDBC with MySql
  • javascript variables, What does var x = a = {} do?
  • Importing Excel files with a large number of columns header into mysql with c#
  • R sqldf renaming a field in a select statement
  • .NET video play library which allows to change the playback rate?
  • How to 'create temp table as select' in Slick?
  • MySQL Order by column = x, column asc?
  • What and where is mdimport
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • How can I send an e-mail from a vbs script
  • Change JButton Shape while respecting Look And Feel
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Get object from AWS S3 as a stream
  • Can Jackson SerializationFeature be overridden per field or class?
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Validaiting emails with Net.Mail MailAddress
  • MySQL WHERE-condition in procedure ignored
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • Javascript + PHP Encryption with pidCrypt
  • Weird JavaScript statement, what does it mean?
  • jQuery tmpl and DataLink beta
  • Web-crawler for facebook in python
  • trying to dynamically update Highchart column chart but series undefined
  • how does django model after text[] in postgresql [duplicate]
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • How to get Windows thread pool to call class member function?
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal