3

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

Raphael Caixeta
  • 7,808
  • 9
  • 51
  • 76
  • 1
    some code would be useful too – bshirley Jun 17 '11 at 14:40
  • Does this help - http://bcaccinolo.wordpress.com/2010/12/28/uitextfield-with-the-keyboard-automagically/ - assuming your modal view controller is being pushed and you want the keyboard to be shown immediately. – petert Jun 17 '11 at 14:56
  • How did you fix this? I have been having a similar problem, posting your solution would be helpful – Veeru Nov 04 '11 at 08:13

2 Answers2

4

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

Chip Coons
  • 3,201
  • 1
  • 24
  • 16
0

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.

Berik
  • 7,816
  • 2
  • 32
  • 40