2

I have a decimal pad that appears after I pressed a UIButton.

I have overridden touchesBegan method like the following:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    self.view.endEditing(true)
}

It works fine as long as for example I don't press another UIButton for example.

My question: is there a way to make my decimal pad disappear other than to make it disappear when I am handling the other UIButton's action? Like if I have 10 other UIButton, it would be a bit annoying to specify every time "of by the way, before you execute your code, check if by any chance the decimal pad is hidden or not"

Nico
  • 6,269
  • 9
  • 45
  • 85

1 Answers1

0

What are you using the DecimalPad for? If you are entering details in a text box the following will dismiss the keyboard (You will need to make your class a delegate of UITextField)

-(BOOL) textFieldShouldReturn:(UITextField*) textField {
    [textField resignFirstResponder];
    return YES;
}

(objective c, not familiar with Swift notation)

mikejl
  • 1
  • 2
  • Yes I do it as well but it doesn't work if I click on a button or a segment control. What do you mean what I use it for? I need it to input some numbers. – Nico May 17 '15 at 11:38
  • Sorry, my mistake - there is no return key on a numeric keypad. have a look at this post which shows how to add a toolbar above the keyboard, so you can add your own 'Done' button to dismiss the keyboard [how-to-add-toolbar-above-keyboard](http://stackoverflow.com/questions/23904848/how-to-add-toolbar-above-keyboard) – mikejl May 17 '15 at 16:36
  • I did add a return key already. I want to be able to dismiss it by clicking anywhere else as well – Nico May 17 '15 at 21:52