I have filled my view with ScrollView (same size as the view) and I'm stuck at how to resign first responder when user tap elsewhere in the View (or the scrollview). Any idea on how to do that ? I'm using the following method but it's not working as expected:
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
Thx for helping,
Stephane
Create a big button behind it all, and the button's callback calls
resignFirstResponder
to every input you have. Just make sure to put everything that the user interacts with on top of the button.Of course the button will be custom rect and transparent.
I would look into implementing an IBOutletCollection called resignables and set every input to that collection. And the button callback iterates over that collection calling
resignFirstResponder
to them all.Edit: if it is a re-sizable scroll view, remember to correctly set the re-size markers in the button's view option, that way the button will always expand and contract to the scrollview's height and width
The best option is the shortest way ;)
Nobody has yet presented the best answer here:
From the documentation on this method:
I bolded the relevant part of that paragraph. By specifying
nil
for theto:
parameter, we automatically call the given selector on the first responder, wherever it is, and we don't need to have any knowledge of where in the view hierarchy it is. This can also be used to invoke other methods on the first responder as well, not just cause it to resign first responder status.and selector
Create your IBOutlet in ViewController.h file like below:
Add this to your ViewController.m file:
like below: