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?
views:
127answers:
1
+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
2010-04-21 14:12:53
Can you please elaborate with more sample code? I'm not sure what you are suggesting?
MikeN
2010-04-21 14:22:56
see the last edit.
gammelgul
2010-04-21 14:37:08
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
2010-04-21 14:59:47
This code doesn't seem to work on Modal Form popups?
MikeN
2010-04-29 17:40:20