3

This line of code is ran when my email textField editingDidEnd. The NSLog runs so I know the function is ran but the keyboard still does not go away. Ive connected the textBox as a delegate. Ive made sure the connections in storyboard are there. It still wont change. Help. Thanks.

- (IBAction)emailDone2:(id)sender
{
    [_email resignFirstResponder];
    NSLog(@"emailDone2");
}

EDIT ** I changed the code as instructed and this still does nothing. Nothing has changed.

- (IBAction)emailDone2:(id)sender
{
    [self.view endEditing:TRUE];
}
Johnny Cox
  • 1,873
  • 3
  • 17
  • 17

2 Answers2

5

The problem is that who you think is first responder and who is first responder may not be the same. Fortunately, there's already a method that will fix this up. Try using

[topView endEditing:YES];

where topView is the topmost view. endEditing will recurse through the subviews, find the one that is first responder, and tell it to resign first responder. This is much simpler than tracking which subview has it.

Found this in keyboard not responding to resignFirstResponder, linked in the sidebar to this question.

Joe McMahon
  • 3,266
  • 21
  • 33
  • I'm not 100% on what topView is and where this should go in my program. My viewController has text boxes and when the user finishes in one and touches the screen anywhere else I want the keyboard to go away. – Johnny Cox Mar 04 '14 at 02:56
  • Try sending it to your main view controller; it should find the one with first responder for you and tell it to send the keyboard away. – Joe McMahon Mar 04 '14 at 18:59
0

The return value of textViewShouldEndEditing should be true for the resignFirstResponder to dismiss

BASIL BABY
  • 73
  • 2