Forum Archive

Remove focus from text field/resign keyboard

Jonstieg

I have a UI with three text fields and one button. All three text fields use the Number Pad keyboard, which don't have a Return key to hide the keyboard.
What I'm looking for is that when I tap the button, the text field that has the focus (one always does), loses focus. I don't know which text field will have the focus when the button is tapped.
All the text field implement delegates.

My first thought was to send a simulated return key with the button tap, but I couldn't figure out how to do this. I tried the textfielf.end-editing() with a couple of different delegate methods, but it didn't work.

Can anybody suggest a way to remove the focus from a text field?
Thanks

ccc

See http://omz-forums.appspot.com/pythonista/post/6456855224123392

Using delegate.textfield_should_begin_editing() or delegate.textfield_did_begin_editing() you should be able to keep track of which of the three fields has the focus. When the button in tapped, you could call textfield.begin_editing() on one of the two other textfields.

Jonstieg

That's a very slick solution. I actually made a dummy text field, hid it behind another field, and set the focus to that on button press.

Thanks so much. I push this app on people like a drug dealer. I love it.

ccc

You can hide your dummy text field by setting its height and/or width to zero.