4

HI all,

I am having a 2 textFeild and 1 textview.

out of 2 textfeild,one textfield requires number to be filled in there. so for that i hv provided numeric keyboard. i m not able to dismiss numeric keyboard,since i cant c any option to hit the numeric keyboard dismiss.

is it possible to dismiss numeric keyboard ??

if yes than can anyone guide me through.

regards shishir

swiftBoy
  • 35,607
  • 26
  • 136
  • 135
Shishir.bobby
  • 10,994
  • 21
  • 71
  • 100

3 Answers3

2

You have 2 options: add a return keyboard in a numpad keyboard or catch the event of user select another textfield and dismiss the numpad there. Here is the link to add a return (done) button to a numpad keyboard. Done in numpad keyboard

vodkhang
  • 18,639
  • 11
  • 76
  • 110
  • 2
    For the record, adding buttons to the standard keyboards is completely unsupported and likely to break. All the implementations I've seen on the net fail in various cases, for example when moving between textfields with different styles, or on the iPad which uses a different keyboard completely. – Mike Weller May 29 '10 at 13:01
  • @vodkhang this is ultimate tutoriaqls man http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key#idc-cover ...thank for the post – Shishir.bobby May 29 '10 at 13:46
  • uhm... interesting... although I never see it fail on my application yet. I will remember this. Thanks – vodkhang May 29 '10 at 13:48
  • but just one more question as i already mentioned, i hv two textfeilds one contain numbers and the other one can contain characters. i implemented the code of urs.. when hit numeric textfild, ,numeric keyboard rises with done button, button,but when i hit the other textfeild,the character keyboard arises,with done button of numeric keyboard still there////...... wat should i do to remove this rthanks a lot for the link again – Shishir.bobby May 29 '10 at 13:58
  • Can you check if the - (void)keyboardWillShow:(NSNotification *)note { is called again. If it is, you have to remove the observer using: [[NSNotificationCenter defaultCenter] removeObserver:self]; at an appropriate place – vodkhang May 29 '10 at 14:22
1

There is no button to dismiss the numeric keypad (although on the iPad you can do this). You will have to call [textfield resignFirstResponder] in code if you want to do this yourself.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
  • Question Mike, what event allows you to know that the user has clicked somewhere other than your textfield? I thought it would be EdittingDidEnd but that doesn't seem to be the place to do the ResignFirstResponder. – Driss Zouak Apr 03 '11 at 16:39
0

There is one other possible way. For those who are looking for something perfect then vodkhang's answer is very good. But if you are looking for some work-around then textField.inputAccessoryView can be useful. The idea is to show done button in inputAccessoryView. Following is sample code

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 25)];
view.backgroundColor = [UIColor grayColor];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Done" forState:UIControlStateNormal];
button.frame = CGRectMake(320-60, 0, 60, 25);
[view addSubview:button];
textField.inputAccessoryView = view;

There are few things to be noted.

  • Width of accessoryView is equal to screen width. So you need to write some code for managing look and feel according to your application.
  • You can give any kind of look to you dome button. And here you don't have to worry about Apple's design changes in keyboard.
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Mohammad
  • 1,636
  • 1
  • 13
  • 17