目前我在iPhone应用程序中工作,使用UITextField输入电话号码,用户输入电话号码,然后如何隐藏键盘?因为这里没有返回按钮,是否可以在键盘内添加完成按钮,请帮帮我
先谢谢
答案 0 :(得分:2)
Here是一个很好的教程。
答案 1 :(得分:1)
答案 2 :(得分:0)
阅读此链接并尝试在您的应用程序中进行编码....
http://iphone-rahulvarma.blogspot.in/2012/03/numericpad-with-done-button.html
答案 3 :(得分:0)
您可以使用“应用”和“取消”按钮添加inputAccessoryView,然后关闭数字键盘。
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];
}
答案 4 :(得分:0)
不使用完成按钮,您也可以通过触摸视图中的任何位置来隐藏数字键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[yourtextfieldname resignFirstResponder];
}