Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close the keyboard on UITextField

Tags:

I'm a newbie developing for iOS devices. I inserted an UITextField on InterfaceBuilder, and I assigned with the code:

 @interface ComposeViewController : UIViewController {  id <ComposeViewControllerDelegate> delegate;  IBOutlet UITextField *notificationTitle; } 
How I could allow to close the keyboard when the user press the "Return" key?
like image 441
Francesc Avatar asked Jan 21 '11 17:01

Francesc


People also ask

Which delegate function removes keyboard in UITextField?

If you have a UITextField and you want to hide the keyboard when the user is pressing the return key, use the textFieldShouldReturn function. Be sure you have set the textField. delegate = self in your viewDidLoad() function.

How do I close the keyboard in Swift?

Microsoft SwiftKey does not have a dedicated minimize keyboard button. Instead, if you slide a finger down the keys from top to bottom, your Microsoft SwiftKey Keyboard is minimized.

Which method can be used to dismiss the system keyboard if a UITextField or Uitextview is currently being edited?

You can ask the system to dismiss the keyboard by calling the resignFirstResponder method of your text field. Usually, you dismiss the keyboard in response to specific interactions. For example, you might dismiss the keyboard when the user taps the keyboard's return key.

How do I turn off textField keyboard?

The UITextField's inputView property is nil by default, which means the standard keyboard gets displayed. If you want to hide both the keyboard and the blinking cursor then use this approach: -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField { return NO; // Hide both keyboard and blinking cursor. }


2 Answers

Set the Delegate of the UITextField to your ViewController, add a referencing outlet between the File's Owner and the UITextField, then implement this method:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {    if (textField == yourTextField) {        [textField resignFirstResponder];    }    return NO; } 
like image 127
Lyle Pratt Avatar answered Sep 28 '22 07:09

Lyle Pratt


Inherit UITextFieldDelegate protocol In viewDidLoad method set:

yourTextField.delegate = self 
Implement the delegate method below:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {     [yourTextField resignFirstResponder];    return NO; } 
like image 24
Guilherme Defreitas Avatar answered Sep 28 '22 07:09

Guilherme Defreitas