tags:

views:

127

answers:

1

On iPad/iPhone, Do you still need to make an invisible button on background to let users exit entries? Is there a better way to dismiss the keyboard when users click outside of an entry?

+2  A: 

I use

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

in the ViewController to call resignFirstResponder on the active control from there.

// edit:

My Views contain several UITextFields; I want the keyboard to disappear when the user touches anywhere besides a TextField or the keyboard, so my ViewController has this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [currentTextfield resignFirstResponder];
}

This causes the keyboard to disappear. (I keep track of the current textfield elsewhere.)

gammelgul
Can you please elaborate with more sample code? I'm not sure what you are suggesting?
MikeN
see the last edit.
gammelgul
Wow, thank you! This works great! I don't even track the currentTextField, I just resignFirstResponder on every single text input on the screen which seems to have no bad side-effects.
MikeN
This code doesn't seem to work on Modal Form popups?
MikeN