Is it possible to add done button inside the keyboard in iphone?

蹲街弑〆低调 提交于 2019-12-11 04:39:34

问题


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


回答1:


Here is to be a good tutorial about this.




回答2:


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.




回答3:


read this link and try to code in your applications ....

http://iphone-rahulvarma.blogspot.in/2012/03/numericpad-with-done-button.html




回答4:


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];
}



回答5:


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];
}


来源:https://stackoverflow.com/questions/12297099/is-it-possible-to-add-done-button-inside-the-keyboard-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!