Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView in inputAccessoryView will not resignFirstResponder

I have a view of a UIViewController which has a UITextField as a subview. The text field implements an event on UIControlEventEditingDidBegin. This event sets the inputAccessoryView of the text field and adds a "shadow" view on the view of the view controller to block interaction with the view.

The inputAccesoryView is a UIView with a UITextView as subview. The UITextView is set as firstResponder when the keyboard shows (registered on UIKeyboardDidShowNotification).

When the "shadow" view is touched I call the following method:

-(void)dismissKeyboard
{
    self.dimScreenView.alpha = 0.0f;
    self.writingView.txtView.text = @"";

    [self.writingView.txtView resignFirstResponder];
}

But the keyboard does not disappear when the shadow view is touched. I have tried calling the [self.writingView.txtWritingField endEditing:YES] and [self.writingView endEditing:YES], but I cannot make it work.

Should I do something special to make the keyboard disappear when the inputAccessoryView has a subview, that is firstResponder?

Update:

It turns out, that the UITextView and UITextField both returns NO on the isFirstResponder property, even if I do not call resignFirstResponder. How can none of the text views be firstResponder while the keyboard is still present?

like image 354
ThomasCle Avatar asked Feb 03 '14 08:02

ThomasCle


1 Answers

like @malex said, after [self.writingView.txtView resignFirstResponder];, your UITextField becomes the first responder again. So you should add the code let the UITextField resign first responder too:

-(void)dismissKeyboard
{
    self.dimScreenView.alpha = 0.0f;
    self.writingView.txtView.text = @"";

    [self.writingView.txtView resignFirstResponder];
    [yourTextField resignFirstResponder];
}
like image 138
Gon Avatar answered Nov 18 '22 06:11

Gon