No UIControls responding to user events
-
29-09-2019 - |
Question
I am creating an iOS app without using Interface Builder and I seem to be missing something vital whereby the controls I am creating (UITextField
, UIButton
, etc.) are not responding to touch events.
Here's my view hierarchy:
UIWindow->UIView->(UITextField, UIButton)
I am able to create the above hierarchy and everything is showing up fine on the screen, but tapping on the UITextField
or the UIButton
do nothing. I also tried adding some UIGestureRecognizer
subclass instances to the UIView
to no avail.
I am able to call becomeFirstResponder
on the UITextField
and the application starts with the keyboard up and able to receive input. However when the keyboard is dismissed the interface goes back to its "dead" mode.
What am I missing?
Solution
I was calling init
on my UIWindow
instead of initWithFrame:
. For some reason everything was drawing correctly but the UIWindow
was not responding to events because every user tap was outside the bounds of the zero-size window.