1

I want my UITextField's keyboard to stay open for the entire time I use this view controller. I don't want it to only open when my user touches the text field. In order to do this, I was hoping I would call the textFieldShouldBeginEditing method by doing this:

EDIT: thanks everyone, I just noticed I called my UITextField a UIImage field for some reason in the interface.  
9
  • 2
    use [self.myTextField becomeFirstResponder] in viewDidLoad.
    – CRDave
    Jun 20, 2013 at 19:35
  • @CRDave - Are you sure it is not viewDidAppear instead of viewDidLoad method?
    – sangony
    Jun 20, 2013 at 19:38
  • na doesn't work @CRDave
    – bmende
    Jun 20, 2013 at 19:45
  • 1
    @bmende either your outlet to (or code to establish) your textfield is not setup, or you are calling the textField's delegate or you do not have viewDidAppear's full parameter listing (the animated part). The solutions given to you will work if you have the background elements established properly. Post more code/information if you are still having problems.
    – Firo
    Jun 20, 2013 at 19:51
  • 1
    Your textField is a UIImageView?!
    – Firo
    Jun 20, 2013 at 20:00

2 Answers 2

2

The textFieldShouldBeginEditing delegate method is not something that you call from your code. The OS calls the method when that particular event occurs, and you put code in there to run when the event is fired (similar to putting code in viewDidLoad for your view controller).

To show the keyboard whenever the view controller appears, simply call the UITextField's becomeFirstResponder method in the view controller's viewDidAppear method like this:

[self.myTextField becomeFirstResponder];

Don't forget to create an IBOutlet parameter for the UITextField, link it in Interface Builder, and replace self.myTextField above with the outlet that you created.

0
1

You should trigger your textview in viewDidAppear method:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.myTextField becomeFirstResponder];
}
1
  • 2
    This is the way to do it, are you sure self.myTextField isn't Nil ? Jun 20, 2013 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.