1

Currently i am working in iPhone application, Using UITextField to enter phone number, user enter the phone number, then how to hide the keyboard? because no return button here, Is it possible to add done button inside the keyboard, please help me

Thanks in Advance

Below mentioned image for your reference, empty space in left corner to add done button, Is it possible?

GingerHead
  • 8,130
  • 15
  • 59
  • 93
SampathKumar
  • 2,525
  • 8
  • 47
  • 82
  • Sounds like you'd need to roll your own On-screen keyboard... – Shark Sep 06 '12 at 09:36
  • I know exactly what you mean, I had the same issue. however I didnt end up making a new OSKB but rather bound the "done" button on a unused key on the remote. Maybe you can get the same behaviour if you try to use the back button as done and override onBackPressed(); – Shark Sep 06 '12 at 09:37
  • i didn't understand your comments – SampathKumar Sep 06 '12 at 09:41

4 Answers4

2

Here is to be a good tutorial about this.

Kai Huppmann
  • 10,705
  • 6
  • 47
  • 78
1

Refer this link. It shows how to add "Done" button in key board.

But I would suggest you to use inputAccessoryView instead. Refer this SO post.

And Must read this SO answer.

Community
  • 1
  • 1
Maulik
  • 19,348
  • 14
  • 82
  • 137
0

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];
}
Jignesh B
  • 490
  • 7
  • 18
0

Without using done button you can also hide numeric keyboard this way by touching anywhere on the view

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [yourtextfieldname resignFirstResponder];
}
Abhinandan Pratap
  • 2,142
  • 1
  • 18
  • 39