I have 6 UITextFields created in Interface Builder. After entering the values, and clicking the search button, I need to dismiss the keyboard from the view.
Currently I'm using 'findAndResignFirstResponder' and have delegates set for all text fields however the keyboard is not dismissing.
Any idea why this isn't working? Is there a better way to dismiss the keyboard?
use this
[self.view endEditing:YES];
this will resign keypad from all fields
in the IBaction "search"
[Field1 resignFirstResponder];
[Field2 resignFirstResponder];
[Field3 resignFirstResponder];
[Field4 resignFirstResponder];
[Field5 resignFirstResponder];
Try using [Field resignFirstResponder];
You could try to assign a UITextField to the FirstResponder and after that to resign the FirstResponder:
[someField becomeFirstResponder];
[someField resignFirstResponder];
Related
I have a app I'm making that has 2 text fields and buttons below it. When the user starts to type, the keyboard comes up and covers the buttons. Is there a way to make the keyboard go away?
There are two ways to do so
// this one line will dismiss the keyboard from anywhere in your code
[self.view endEditing:YES];
or
with the delegate of textfield (you should declare it in your .h file first)
#interface someController : UIViewController <UITextFieldDelegate>
and the in .m
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
// next line will dismiss the keyboard
[textField resignFirstResponder];
return YES;
}
Check UITextField documentation:
To dismiss the keyboard, send the resignFirstResponder message to the text field that is currently the first responder. Doing so causes the text field object to end the current editing session (with the delegate object’s consent) and hide the keyboard.
In other words, just send resignFirstResponder to an active text field object.
I use this:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
[self.alertView dismissWithClickedButtonIndex:self.alertView.firstOtherButtonIndex animated:YES];
return YES;
}
In the view controller after setting the text field delegate to self.
I dropped a UITextField into a view controller via Interface Builder called *txtNameField, added the UITextFieldDelegate to my view controller, and then set the field's delegate to self in the viewDidLoad of the view controller. I made a call to
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
NSLog(#"textFieldShouldReturn");
[textField resignFirstResponder];
return YES;
}
but the return key does not dismiss the keyboard.
Any ideas?
Link a method to your textField's didEndOnExit event and put [textField resignFirstResponder]; in that method.
When the view is dismissed the keyboard slides after the view.
I created a video to demonstrate the problem.
http://www.youtube.com/watch?v=ISFL5G17coU'
Does anyone know why this happens
In -(void) viewWillDisappear: make sure you call resignFirstResponder on your textfield.
- (void)viewWillDisappear:(BOOL)animated
{
[textField resignFirstResponder];
}
I got one UITextField on my Modal view controller.
When "Done" key is clicked, i want to dismiss the modal view.
i don't know where should i add below code to dismiss modal view.
Thanks in advance for any help.
[self.parentViewController dismissModalViewControllerAnimated:YES];
add it in UITextFieldDelegate method
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
[self.parentViewController dismissModalViewControllerAnimated:YES];
return YES;
}
I use a UITextView in my application. The text editing is ok. I set the return button to Done.
When I finish the editing, I like to hide the keyboard with the done button.
My Question: How can I set the done button?
Thanks,
Balu.
Set your controller as the textField's Delegate, implement UITextField Delegate method textFieldShouldReturn in your controller and resign first responder before returning TRUE/YES:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}