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 @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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With