Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

like image 657
Sharanya Avatar asked Sep 28 '12 12:09

Sharanya


4 Answers

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.

like image 78
Paresh Navadiya Avatar answered Nov 20 '22 22:11

Paresh Navadiya


check your .h file if you have put the TextFieldDelegate over there. . Some time if we not declare its delegates function doesn't work properly.

like image 4
B25Dec Avatar answered Nov 20 '22 20:11

B25Dec


I think when you are setting the text, textField mileagerate is becoming first responder again, so use this statement at last of the method

[mileagerate resignFirstResponder];
like image 1
Avadesh Yadav Avatar answered Nov 20 '22 22:11

Avadesh Yadav


You have to first use a [UIView setAnimationDidStopSelector:@selector(yourMethod)];

Then in the "YourMethod" resign your keyboard.

- (void)yourMethod
{
   [mileagerate resignFirstResponder];
}
like image 1
Sham Avatar answered Nov 20 '22 22:11

Sham