I have a UITextView
. I implemented a navigationBar UIBarButtonItem
to respond to a touch and resign the firstResponder for my UITextView
.
But, when the selector method is called, the keyboard doesn't get dismissed. I checked the UITextView's responder status with isFirstResponder
and it returns YES. I also checked it with canResignFirstResponder
and the return value is NO.
I must be missing something here...why is it returning NO?
I get that I can override canResignFirstResponder
by subclassing UITextView, but I'd like to avoid that if possible.
Here's a code snippet:
- (void) commentCancelButtonTouched:(id)sender
{
NSLog(@"Cancel button touched");
[self.navigationBar popNavigationItemAnimated: NO];
if ([self.textInput.textView canResignFirstResponder] == NO) {
NSLog(@"I don't want to resign!");
}
[self.textInput.textView resignFirstResponder];
}
Just in case anyone wants to hide the keyboard when you touch outside of the textview, it's pretty easy...
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self.xFront resignFirstResponder];
}
xFront is my outlet to my UITextView
.
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