Shankar Naik
Shankar Naik

Reputation: 411

is it right to use BecomeFirstResponder in viewDidLoad

I want to bring the keyboard up for a textfield when a viewcontroller is opened.

so I am calling becomefirstresponder on textfield and it always works.

But I wonder

  1. Is it right place to call becomefirstresponder ? or do I have to call in some other life cycle event in viewcontroller
  2. if view did load is the right place to call.. do I have to manually call in main thread or not required as by default view didload is required ?

Upvotes: 0

Views: 773

Answers (1)

matt
matt

Reputation: 535999

There's nothing absolutely wrong with what you're doing.

Logically one might argue that viewDidLoad is too soon, since your view (with your text field) is not in the interface; perhaps viewDidAppear would be a more logical place. In that case, though, you have to keep in mind that viewDidAppear can be called multiple times during the view controller's lifetime, so you'd need to distinguish whether this is the first time (not hard).

Upvotes: 1

Related Questions