UIViewController
inherits from UIResponder
so a naive way (I am pretty sure is not the smartest way to do it) would be by overwriting the following methods (at least 1 of them)
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
- touchesCancelled:withEvent:
Next you could get the touched view by doing
UITouch *touch = [touches anyObject];
UIView *touchedView = [touch view];
finally resign the first responder if that view is not your text field
if(touchedView != textField){
[textField resignFirstResponder];
}
_
Demerits of this approach:
You will have to handle the "tap" by yourself. (Same problem as the old iOS 3.1 or earlier). You will have to come up with your own implementation to differentiate single taps from drags, swipes, double taps, long taps, etc. Is not hard to get it working well but it is not likely you get it exactly the same way Apple detects taps (timings, distances, thresholds count!)
However, that depends on your needs.
If your view structure is simple enough then you could add a gesture recognizer to the container view and resign the first responder every time the handler is called :)
Hope this helps