How to dismiss number pad keyboard by tapping anywhere How to dismiss number pad keyboard by tapping anywhere ios ios

How to dismiss number pad keyboard by tapping anywhere


Declaring the text field as instance variable or property if it isn't already and implementing a simple method like this:

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

will do just fine.


Try this method,

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{   [self.view endEditing:YES];}

Now tap anywhere and see keyboard will dismiss. :-)


For Swift Use Below Code

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {       textFiled.resignFirstResponder() }

Check out latest update on following Link