ResignFirstResponder not working

Sharanya picture Sharanya · Sep 28, 2012 · Viewed 12.9k times · Source
-(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 resign first responder in various places in my app. But when i click on this button alone, the keyboard does not disappear. If i click on the return key in keyboard, the entered value disappears.

Answer

Paresh Navadiya picture Paresh Navadiya · Sep 28, 2012

Use below line of code 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.