Keyboard hidden after becomeFirstResponder
-
29-10-2019 - |
문제
I'm bringing focus to a UITextView after setting its .hidden property to NO. When I set the [textView becomeFirstResponder] the textView gets the little typing cursor, but the keyboard remains hidden. Any idea why? If it helps, the main view is a modal view that a UINavigationController is presenting.
EDIT: Here's the method that gets called:
- (void)show_comment_elements {
toolbar.hidden = YES;
main_table.hidden = YES;
add_comment_table.hidden = NO;
comment_text.hidden = NO;
[comment_text becomeFirstResponder];
}
Here's a screenshot:
해결책
I'm assuming you've verified that your method is getting invoked after the view is placed on-screen.
From the docs....
A responder object only becomes the first responder if the current responder can resign first-responder status (canResignFirstResponder) and the new responder can become first responder.
You may call this method to make a responder object such as a view the first responder. However, you should only call it on that view if it is part of a view hierarchy. If the view’s window property holds a UIWindow object, it has been installed in a view hierarchy; if it returns nil, the view is detached from any hierarchy.
So:
Can you confirm that the current responder when your method is invoked can resign first-responder status?
Your view appears to be in the view hierarchy if it is displaying from the screen shot. If the screen-shot is from IB, then test that the view's window property is not nil.
Make sure the view is editable -- if(comment_text.isEditable) or it will not accept first responder status.
Try adding [comment_text setNeedsDisplay] to force a re-fresh with the view set as first responder.
If none of this works, post some more code (such as where the method is being called from).
다른 팁
This problem also occurs when you modify the nextResponder
on some object in the chain, so that the responder chain does not go to the UIWindow
.