1

I am writing an iPhone app with a keypad and two TextFields on a single view. The user types into each of the text fields. Because I want to use an on-screen keypad, I disabled the the keyboard from launching when each TextField is selected. (I used the method suggested in this thread:

Disable UITextField keyboard?

So far so good EXCEPT the cursor doesn't blink in the either of the two TextFields until they are selected. If I just begin typing without selecting, the first textfield is filled. That's OK, but I would like to set the cursor flashing in that field so the user is notified that that is where the input will go unless they select the other field.

I did not create the text fields programatically. I created them with Interface builder.

  1. How do I programatically select the desired starting text field (ideally some highlight would show up when selected). Right now I just got lucky and the field I want to be the default is the default.

  2. How do I place the flashing cursor onto the right side of that text field.

...Dale

Community
  • 1
  • 1
Dale Dietrich
  • 7,196
  • 4
  • 21
  • 25

2 Answers2

4

Call [myTextField becomeFirstResponder]; this will notify the receiver that it is about to become first responder in its window. That should set the Cursor in the UITextField.

Joe
  • 2,987
  • 15
  • 24
2

To programmatically activate a field and make it your starting text field you should use UIResponder's becomeFirstResponder method, which all UITextFields inherit from.

[textField becomeFirstResponder];
Joe
  • 2,987
  • 15
  • 24
8vius
  • 5,786
  • 14
  • 74
  • 136
  • Thanks 8vius. I saw Joe's response first. You probably posted it at the same time. Your collective answer worked great! – Dale Dietrich Sep 05 '12 at 00:58