-1

I have a UITextField which is Number Pad and its properties look like

enter image description here

But when I run my application, I do not see Done on my screen

enter image description here

What is the issue? How can I get Done on Decimal Pad?

daydreamer
  • 87,243
  • 191
  • 450
  • 722
  • The Decimal pad doesn't show the return key (regardless of its label). You need to create a view with a button and make it the text field's `inputAccessoryView`. – rmaddy Jan 10 '15 at 22:10
  • For inspiration, have a look [here](https://horseshoe7.wordpress.com/2012/08/17/tutorial-creating-a-done-button-on-the-iphone-number-pad-keyboard/) and on this question: http://stackoverflow.com/questions/584538/how-to-show-button-done-on-number-pad-on-iphone – Emil Jan 10 '15 at 22:11
  • Can you guide me to what's needed? Sorry I am new to it, any references I should read up? – daydreamer Jan 10 '15 at 22:11

1 Answers1

0

The best way I've found when doing something like this is to append an inputAccessoryView to the UITextField. That input accessory view can have a "Done" button on it that dismisses the keyboard for you. I don't think you should put a "Done" button on the key pad itself, because where would it go?

Here's how I've done it before:

- (void)setupKeyboardAccessory {
    UIToolbar *keyboardToolbar        = [[UIToolbar alloc] init];
    [keyboardToolbar sizeToFit];
    keyboardToolbar.backgroundColor   = [UIColor whiteColor];
    UIBarButtonItem *flexBarButton    = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *doneBarButton    = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self.patientAgeTextField action:@selector(resignFirstResponder)];
    keyboardToolbar.items             = @[flexBarButton, doneBarButton];
    self.textField.inputAccessoryView = keyboardToolbar;
}
mbm29414
  • 11,558
  • 6
  • 56
  • 87