问题
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