I want to add a code where if the user tap anywhere outside the Text Field, the keyboard will close. So I met this answer. But I don't know how to implement the binding to the function touchesBegan because I alloc all the view component programmatically, including the subview container and textfield within that subview container. How to do that? I think this is just a line of code, but I don't know what code to expect and what words I have to use to search on google (I've tried to search for it but can't quite find what I'm looking for), so I'm lost. Thanks.
Asked
Active
Viewed 219 times
1 Answers
0
Your subclasses of UIView
s can implement touchesBegan. You should put the touchesBegan on the UITextField superview.

John Bennedict Lorenzo
- 527
- 3
- 10
-
Oh, but I have viewContainer as UITextField superview. and the viewContainer has self.view as superview. How can I implement the touchesBegan on the viewContainer? – Chen Li Yong Jan 19 '16 at 02:32
-
Nevermind, it works when I put it at self.view anyway. Thanks! – Chen Li Yong Jan 19 '16 at 02:38
-
As I've read the touchesBegan method is available on UIResponder subclasses. – John Bennedict Lorenzo Jan 19 '16 at 02:39