ResignFirstResponder not working

-(IBAction)settings:(id)sender { [mileagerate resignFirstResponder]; [mainView bringSubviewToFront:mileageView]; mainView.hidden=TRUE; [UIView beginAnimations:@"Settings" context:nil]; [UIView setAnimationDuration:1.0]; [mainView setFrame:CGRectMake(0, 0, 320, 460)]; [UIView commitAnimations]; mileagerate.text = [[NSUserDefaults standardUserDefaults] valueForKey:@"savedstring"]; mileageView.hidden=FALSE; } 

I used the resignation of the first responder in different places of my application. But when I press only this button, the keyboard does not disappear. If I press the return key on the keyboard, the entered value disappears.

+8
objective-c iphone resignfirstresponder
source share
8 answers

Use the line of code below in your method if you don't know which textfield to resign:

Swift

 self.view.endEditing(true)//resign current keyboard 

Objective-c

 [self.view endEditing:YES]; //resign current keyboard 

EDIT : Note . It will resign keybord from your current view .

+25
source share

check your .h file if you placed TextFieldDelegate . For a while, if we do not announce that its delegates function is not working properly.

+4
source share

I think that when you set the text, textField mileageate becomes the first responder again, so use this statement at the end of the method

 [mileagerate resignFirstResponder]; 
+1
source share

You must first use [UIView setAnimationDidStopSelector:@selector(yourMethod)];

Then in " YourMethod " cancel the keyboard.

 - (void)yourMethod { [mileagerate resignFirstResponder]; } 
+1
source share

Be sure to enable the return key to cancel the first retry.

On the “Connections” tab, change the connection to “Finish at the exit” and connect to the control keyboard return key (orange ball) to DONE.

0
source share

Try the following:

 if([mileagerate isFirstResponder]) [mileagerate resignFirstResponder]; 
0
source share

In Swift 2, you can use below 3 different types to reject the keyboard (assuming there is a text box and a button

  import UIKit class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet var userInputField: UITextField! override func viewDidLoad() { super.viewDidLoad() //Important if you are using textfieldDelegate self.userInputField.delegate = self } @IBAction func findAgeBtn(sender: UIButton) { //1. keyboard to disappear when button clicked dimissKeyboard() } //2. keyboard to disappear when touched anywhere on the view override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { self.view.endEditing(true) } //Function for option 1 func dimissKeyboard(){ self.view.endEditing(true) } //3. keyboard to disappear when clicked on the Return key. Don't forget to set the delegate to self func textFieldShouldReturn(textField: UITextField) -> Bool { textField.resignFirstResponder() return true } } 
0
source share

1.Check UITextFieldDelegate,

 class YourClass : UIViewController,UITextFieldDelegate{ 

2. Then reinstall the "Must complete editing" function to return it to "Yes"

  func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { return true } 
0
source share

All Articles