Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I dismiss keyboard when I will just touch anywhere except UITextField?

Hello I have two UITextFields in my application, and want to dismiss the keyboard when I just touch anywhere except the UITextFields how can I do this?

like image 251
Chatar Veer Suthar Avatar asked Feb 09 '11 04:02

Chatar Veer Suthar


1 Answers

use tochesBegin method for this purpose

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

  [yourFirstTextField resignFirstResponder];
  [yourSecondTextField resignFirstResponder];
}

You do not need any thing else.When you touch anywhere on view then both textField resign no need to to know which one having focus.and when you touch textField then textField open keyboard by own.

like image 172
Ishu Avatar answered Oct 10 '22 19:10

Ishu