Question

I created an app in where i have appdelegate class only. I dont create a UIView or a view controller. I just added textFields, labels and buttons in my window.

I want to hide the keyboard when the user taps out of the text boxes. This is normally achieved by the method touchesBegan. For implementing this method, two things we need to do.

One is add in the header file(.h)

Another one is set the textField's delegate. Thats is, textField.delegate=self;

I did those two things. But still the touchesBegan method did not called.

Why? Should i have a UIView or UIViewController class for it?

Thanks in Advance

Was it helpful?

Solution

touchesBegan is a UIView method. if you want to do it in your setup you should create a UIView subclass, put all your controls in that one and implement touchesBegan in the UIView subclass.

OTHER TIPS

UIWindow is a subclass of UIView, so you could just hook into those. But this is a seriously bad design pattern. Consider modifying your application so it uses a single view controller, rather than doing everything in the app delegate. Otherwise you're jury-rigging the app delegate to be something it was never designed to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top