What I want:
A textField
and a textLabel
is included in the tableView
. When the tableView is present the textField
will be the firstResponder
and brings out the keyboard.
Problems I have:
the App is only shows the keyboard if the textField.becomeFirstResponder()
is called within viewWillAppear
or viewDidLoad
(textField
and textLabel
is not showing at all).
How I fixed it:
The bug is not reproducible when I moved the textField.becomeFirstResponder()
call into viewDidAppear
Question:
Am I spouse to call becomeFirstResponder()
function inside the viewDidAppear
function? otherwise the keyboard will block all the other views
Many Thanks
Think about what viewDidLoad
, viewWillAppear
, and viewDidAppear
mean.
viewDidLoad
means that the view controller has a view — but that view is not yet part of the interface.
viewWillAppear
means that the view controller's view will become part of the interface — but hasn't yet.
viewDidAppear
means that the view controller's view did become part of the interface.
You need your view to be part of the interface before your text field can summon the keyboard. Only then is the table view actually showing and configured. In other words, at this point the interface has settled down into its actual form, and we are ready to place the keyboard correctly above it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With