Question

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:

frustration

Was it helpful?

Solution

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:

  1. Can you confirm that the current responder when your method is invoked can resign first-responder status?

  2. 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.

  3. Make sure the view is editable -- if(comment_text.isEditable) or it will not accept first responder status.

  4. 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).

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top