0

I have a CCTextField that is hidden until the user taps on an object, which then adds it to the node tree and it's visible.

Currently, the user must then tap the CCTextField to activate the iOS keyboard and begin entering text.

Is there a way to programmatically initiate the keyboard appearing ?

becomeFirstResponder isn't working.

prototypical
  • 6,731
  • 3
  • 24
  • 34
  • does assigning the textfield `firstResponder` status not work? I haven't used the library, but the documentation on the `CCTextField` class says it encapsulates `UITextField` so I presume it should work the same, no? – Louis Tur Mar 23 '15 at 02:05
  • I presumed it would as well. I did try `becomesFirstResponder` on the text field property initially, but no dice. I think it "should" work, but did find a workaround. But am wondering if possibly I worked around an intentional roadblock :) we shall see... – prototypical Mar 23 '15 at 02:57
  • ahaha, good to know! Thanks for posting an update to this as well – Louis Tur Mar 23 '15 at 22:09

1 Answers1

0

I dug a little deeper into the CCTextField class code, and cocos2D adds the UITextField property as a subview of the cocos2d view.

For some reason though, this didn't work :

[myCCTextField.textField becomeFirstResponder];

This is what I did, and it worked :

[[CCDirector sharedDirector] view]subviews[0] becomeFirstResponder];

If you have multiple CCTextFields you are obviously going to have to determine the index of your desired text field that you'd like to edit.

prototypical
  • 6,731
  • 3
  • 24
  • 34