2013-01-09 52 views
0

我知道這裏有一些關於How to show button ‘Done’ on number pad on iPhone OS 4?的討論關閉數字鍵盤。我想找到一種方法來解除數字鍵盤w/o不得不添加一個UIToolbarButton。我的UITextFields是郵政編碼和age.The mint.com iPhone應用程序這樣做;所以必須有一個方法。關閉UITextField中的數字小鍵盤而不使用UIToolbarButton

這裏是我當前的代碼,增加了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; 
+0

如果你不想爲這個按鈕,什麼e發泄你想觸發鍵盤解僱? – rmaddy

回答

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