Iphone 从没有UIToolbarButton的UITextField中删除数字键盘
我知道这里有一些讨论关于取消一个数字键盘。我想找到一种方法,不需要添加UIToolbarButton就可以关闭数字键盘。我的UITextFields是zipcode和age;所以一定有办法 以下是添加UIToolbarButton的当前代码:Iphone 从没有UIToolbarButton的UITextField中删除数字键盘,iphone,ios,objective-c,Iphone,Ios,Objective C,我知道这里有一些讨论关于取消一个数字键盘。我想找到一种方法,不需要添加UIToolbarButton就可以关闭数字键盘。我的UITextFields是zipcode和age;所以一定有办法 以下是添加UIToolbarButton的当前代码: textField1.keyboardType = UIKeyboardTypeNumberPad; textField1.delegate = self; //Create a toolbar to add to the textpad UIToolb
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;
当用户触摸文本字段以外的任何位置时,我使用此选项关闭键盘:
- (void)touchesEnded: (NSSet *)touches withEvent: (UIEvent *)event {
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[UITextField class]])
[view resignFirstResponder];
}
}
我在这里找到的:
如果您不需要此按钮,您希望触发什么事件来触发键盘?