Hi all,
I've been battling with input TextFields on iOS for a few days now. Maybe someone here will have some insight!
This happens using AIR4.0 and AIR 3.9 (haven't tested older) on iOS7 (iPhone 5) and iOS5.1 (iPad 1) (haven't tested others).
I create an input TextField and place it on the stage, then set focus to it like this (some setup code ommitted for visibility):
_inputTextField = new TextField();
_inputTextField.type = TextFieldType.INPUT;
addChild(_inputTextField);
_inputTextField.addEventListener( FocusEvent.FOCUS_OUT, loseFocus );
_inputTextField.addEventListener( KeyboardEvent.KEY_DOWN, keyDown );
_inputTextField.addEventListener( Event.CHANGE, inputChanged );
stage.focus = _inputTextField;
_inputTextField.setSelection( _inputTextField.text.length, _inputTextField.text.length ); // Place cursor at end
_inputTextField.requestSoftKeyboard();
Here is what happens on iOS:
1) If there is text in the textfield, this code works perfectly.
3) If the text field is empty, the problem below occurs (I think it is because setSelection is unable to set a selection)
2) If I leave out the setSelection line, even with text in the field, the problem below also occurs
4) If there IS text, and I manually hit backspace to delete it all so that the text field is empty, there is no problem
The problem:
When the problem occurs, here are the symptoms:
1) The text field is the correct size/position, but the font is very tiny and is a serif font
2) The KEY_DOWN event only fires for ENTER (not for other keys)
3) The CHANGE event only fires intermittently. Seems to be when the OS suggests spell-check alternatives etc
4) on FOCUS_OUT, reading from _inputTextField.text gives an empty string even if there is text in there
When there is no problem, textfield size, position, font style etc is fine. All key events and change events fire, and reading from textfield.text gives the correct string.
Any help appreciated!
Peter