- Home /
TextField not getting focus on iOS
I've got a little dialog with a GUI.TextField for entering your name when you get a high score. It works fine in the simulator, but on an iPad, it does not work reliably -- the field does not get the focus, no keyboard appears, and you have no way to enter text.
If you let it sit there long enough (like 5 minutes or more), then eventually the field does get the focus, and the keyboard appears.
I'm using the iCadeBinding plug-in, which might have something to do with it, but I disable that while the high score dialog is present. I also tried commenting out the line that enables multitouch input, to no effect. I've also tried explicitly giving focus to the text field (using SetNextControlName/FocusControl), but again, this makes no difference.
Here's the revelant code from OnGUI:
GUI.BeginGroup (new Rect(Screen.width / 2 - kWidth/2, Screen.height / 2 - kHeight/2, kWidth, kHeight));
GUI.Box(new Rect(0,0,kWidth,kHeight), "High Score!"); GUI.Label(new Rect(40,70, kWidth-80,50), "Enter your name:"); GUI.SetNextControlName ("NameField"); playerName = GUI.TextField(new Rect(40,120, kWidth-80,50), playerName); if (GUI.Button(new Rect(kWidth/2-60,kHeight-60,120,50), "OK")) { HighScores.AddHighScore(playerName, GUIManager.Score()); StateManager.SetState(StateManager.kStateHighScoreList); }
// End the group we started above. This is very important to remember! GUI.EndGroup ();
// Make sure the name field has the focus GUI.FocusControl("NameField");
Has anybody seen anything like this? Any idea why my TextField would need five minutes to warm up and present the keyboard?
Answer by JoeStrout · Aug 25, 2012 at 04:26 PM
OK, I've figured it out... it boils down to this problem in iOS: when you have a Bluetooth keyboard connected (which the iCade pretends to be), it is very hard to make the onscreen keyboard ever appear. The reason waiting five minutes would cause the keyboard to finally appear is that in that time, the iCade turns itself off.
Apparently it is possible, though; so I'm currently downloading the latest version of Unity (3.5.5) to try the new TouchScreenKeyboard class. Perhaps with that I can force the soft keyboard to appear despite having an iCade (or other BT keyboard) connected.
EDIT: Nope, TouchScreenKeyboard doesn't work any better than GUI.TextField. With a BT keyboard (such as iCade) attached, no onscreen keyboard appears. So, I guess we'll just have to roll our own. :(
Your answer
Follow this Question
Related Questions
Prevent IOS keyboard from showing 0 Answers
Textfield on Android problem 2 Answers
Can I do this? 1 Answer
Using GUI.FocusControl on TextField selects all text 4 Answers
TouchScreenKeyboard flickers 0 Answers