Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

number pad keyboard not show return key in iphone

Tags:

iphone

ios-4.2

I am new to iPhone technology. I've saved a problem in a iPhone application, but when i use textfield keyboard type number pad the keyboard doesn't show a return/done button.

How can I hide the number pad keyboard after entering the number in the textfield? Do you have any solutions for that. Please provide help.

like image 629
jaydev Avatar asked Apr 29 '11 14:04

jaydev


People also ask

How do I get the return button on my iPhone keyboard?

Depending on the iOS version your device is running and your keyboard settings, the position of the Return key may vary. Sometimes, you may find it as soon as you launch the keyboard, but in a vast majority of cases, you'll be able to access it from the num pad section by tapping on the “123” key.

Does iPhone keyboard have Enter key?

It is replaced with the "Join" key so when you are done entering your password you hit "Join" and it starts the connection process.

How do I change the numeric keypad on my iPhone?

To try it out, simply tap and hold the "123" button while you input numbers or punctuation marks. Once you're finished using the numeric keyboard, let go of the "123" button, and your keyboard will change back to its alphabet mode without the need of an extra tap.


1 Answers

You can do this in this way:

@property (nonatomic, strong) UITextField *textField;

- (void)viewDidLoad {
    [super viewDidLoad];

    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonDidPressed:)];
    UIBarButtonItem *flexableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[self class] toobarHeight])];
    [toolbar setItems:[NSArray arrayWithObjects:flexableItem,doneItem, nil]];
    self.textField.inputAccessoryView = toolbar;
}

- (void)doneButtonDidPressed:(id)sender {
    [self.textField resignFirstResponder];
}

+ (CGFloat)toolbarHeight {
    // This method will handle the case that the height of toolbar may change in future iOS.
    return 44.f;
}
like image 63
Oscar Avatar answered Oct 18 '22 14:10

Oscar