Group Group Group Group Group Group Group Group Group

viewWillApper - chapter 12

#1

Hi All,

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
textField.becomeFirstResponder()
}

The view controller receives the viewWillAppear() message just before it becomes visible. That is a perfect time to make the text field active. You do this by sending it the becomeFirstResponder() message.

I was wondering if I just call textField.becomeFirstResponder() in viewDidLoad. For me it achieved the same thing.Can I ask if it is wrong? If yes why? Could you please give advice on this?

override func viewDidLoad() {
    super.viewDidLoad()
    textField.becomeFirstResponder()
    navigationItem.largeTitleDisplayMode = .never
}

Many thanks

#2

Hi @noah8610, I don’t believe it is necessarily wrong to put textField.becomeFirstResponder() in the viewDidLoad however, it might seem more logical to have it in viewDidAppear because with viewDidLoad the view is not yet part of the interface.

Best,
Gina