0

我知道这里有一些关于如何在 iPhone OS 4 的数字键盘上显示按钮“完成”的讨论?关闭数字键盘。我想找到一种无需添加 UIToolbarButton 即可关闭数字键盘的方法。我的 UITextFields 是邮政编码和年龄。mint.com iPhone 应用程序就是这样做的;所以必须有办法。

这是我当前添加 UIToolbarButton 的代码:

textField1.keyboardType = UIKeyboardTypeNumberPad;
textField1.delegate = self;

//Create a toolbar to add to the textpad
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleDefault;
numberToolbar.items = [NSArray arrayWithObjects:
                       [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
                       [[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(dismissZipKeyPad)],
                       nil];
[numberToolbar sizeToFit];
textField1.inputAccessoryView = numberToolbar;
4

1 回答 1

0

当用户触摸文本字段外的任何地方时,我用它来关闭键盘:

- (void)touchesEnded: (NSSet *)touches withEvent: (UIEvent *)event {
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[UITextField class]])
[view resignFirstResponder];
}
}

我在这里找到了它:

http://remarkablepixels.com/blog/2011/1/23/dismiss-iphone-keyboard.html

于 2013-01-10T03:46:58.850 回答