Odys
Odys

Reputation: 9090

How can I bring keyboard to edit a field when a UIViewController is shown?

I want to show the keyboard just after a view controller is being pushed to start editing a specific UITextField.

I believe that I should manually fire the event on the ViewDidAppear.

Which is the proper way of doing such tasks?

Upvotes: 2

Views: 101

Answers (2)

Maulik
Maulik

Reputation: 19418

for that you need IBOutlet UITextFiled *yourTextField;

- (void)viewDidLoad or viewWillAppear:(BOOL)animated or viewDidAppear:(BOOL)animated
{
  [yourTextField becomeFirstResponder];
}

Upvotes: 1

Vladimir
Vladimir

Reputation: 170829

To make keyboard appear you need to manually set your text field as a first responder:

[textField becomeFirstResponder];

It can be called either in viewWillAppear: or in viewDidAppear: method - whichever provides best behaviour for you.

Upvotes: 3

Related Questions