1

Currently I have a textfield, which pulls up a NumberPad keyboard for input.

I want the NumberPad keyboard layout, but I need a button to resign that responder.

Is there a way to code the UITextField so that it has a NumberPad keyboard and the space on the left of the keyboard which is blank is replaced with a 'Done', 'Send' or 'Go' button.

Or do I need to create a custom inputView for the UITextField?

I would have thought since there is a blank key on the NumberPad apple would have made it useful for something.

OscarTheGrouch
  • 2,374
  • 4
  • 28
  • 39
  • [Duplicate question, please look at here](http://stackoverflow.com/questions/584538/how-to-show-button-done-on-number-pad-on-iphone) [Here is a link to a way to create such a button](http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key) – vodkhang Jun 05 '10 at 02:03

3 Answers3

2

Just try having a UIToolBar with a done button on it as the inputAccessoryView of the text field. In the button click event provide the code to dismiss the keyboard. Think that should suit you.

Or if you want to have a custom button drawn over the keyboard you can search here to get the solution

visakh7
  • 26,380
  • 8
  • 55
  • 69
1

The empty button is needed if you use phonePad. But you can add inputAccessoryView with 'Apply' and 'Cancel' buttons, and dismiss the number pad with then.

inputAccessoryView

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    numberToolbar.barStyle = UIBarStyleBlackTranslucent;
    numberToolbar.items = [NSArray arrayWithObjects:
                         [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)],
                         [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                         [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
                     nil];
    [numberToolbar sizeToFit];
    numberTextField.inputAccessoryView = numberToolbar;
}

-(void)cancelNumberPad{
    [numberTextField resignFirstResponder];
    numberTextField.text = @"";
}

-(void)doneWithNumberPad{
    NSString *numberFromTheKeyboard = numberTextField.text;
    [numberTextField resignFirstResponder];
}
Luda
  • 7,282
  • 12
  • 79
  • 139
0

You need to do a custom inputview now and assign it to the inputview property of your text field. I am currently researching it, but that is the right, approved way of doing it. It seems overkill just for changing a single button though.

Julian
  • 1
  • 1
    http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key has updated content for iOS4.0 – OscarTheGrouch Jul 19 '10 at 19:21