Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从没有UIToolbarButton的UITextField中删除数字键盘_Iphone_Ios_Objective C - Fatal编程技术网

Iphone 从没有UIToolbarButton的UITextField中删除数字键盘

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

我知道这里有一些讨论关于取消一个数字键盘。我想找到一种方法,不需要添加UIToolbarButton就可以关闭数字键盘。我的UITextFields是zipcode和age;所以一定有办法

以下是添加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;

当用户触摸文本字段以外的任何位置时,我使用此选项关闭键盘:

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


如果您不需要此按钮,您希望触发什么事件来触发键盘?