我怎麼能在iPhone消失數字鍵盤因爲它沒有返回鍵,這意味着它不會向Disapperiang IPhone數字鍵盤
- (BOOL)textFieldShouldReturn:(UITextField *)textField
我怎麼能在iPhone消失數字鍵盤因爲它沒有返回鍵,這意味着它不會向Disapperiang IPhone數字鍵盤
- (BOOL)textFieldShouldReturn:(UITextField *)textField
迴應試試這個:
[theTextField resignFirstResponder];
那麼你在我上面寫過的函數中這樣做,就像這樣。 無論如何,我應該把這個代碼工作? – itsaboutcode 2009-09-10 22:53:33
我在我的視圖中有很多文本框,它也不適用於數字鍵盤 – 2012-06-19 13:24:57
下面是答案..
-(void) touchesBegan :(NSSet *) touches withEvent:(UIEvent *)event
{
//[URL resignFirstResponder];
//[Password resignFirstResponder];
[speedField resignFirstResponder];
[super touchesBegan:touches withEvent:event ];
}
當我在一個視圖中有子視圖時不工作 – 2012-06-19 13:22:35
在這裏,你去。用這個擴展你的UIViewController類。但是我們怎麼知道它是完成按鈕? Adding Done Button to Only Number Pad Keyboard on iPhone
//
// UIViewController+NumPadReturn.m
// iGenerateRandomNumbers
//
// Created by on 12/4/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "UIViewController+NumPadReturn.h"
@implementation UIViewController (NumPadReturn)
-(void) viewDidLoad{
// add observer for the respective notifications (depending on the os version)
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
} else {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
}
}
- (void)keyboardWillShow:(NSNotification *)note {
// if clause is just an additional precaution, you could also dismiss it
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 3.2) {
[self addButtonToKeyboard];
}
}
- (void)keyboardDidShow:(NSNotification *)note {
// if clause is just an additional precaution, you could also dismiss it
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
[self addButtonToKeyboard];
}
}
- (void)addButtonToKeyboard {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0) {
[doneButton setImage:[UIImage imageNamed:@"DoneUp3.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown3.png"] forState:UIControlStateHighlighted];
} else {
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
}
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
[keyboard addSubview:doneButton];
} else {
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}
- (void)doneButton:(id)sender {
NSLog(@"doneButton");
[self.view endEditing:TRUE];
}
-1這是一個完全的黑客,不應該使用。如果蘋果決定將「UIKeyboard」的名稱更改爲「UIKBView」,該怎麼辦?您絕不應該依賴未記錄的行爲或實現細節來使代碼正常工作。如果你需要沒有無證材料的行爲,請提交一個錯誤。 – 2010-12-05 21:30:02
爲什麼不使用「Numbers and Punctuation」鍵而不是「Numeric」?這將節省您的時間
使用resignFirstResponder中的touchesBegan,像這樣:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch * touch = [touches anyObject];
if(touch.phase == UITouchPhaseBegan) {
[self.myTextField resignFirstResponder];
}
}
您可能需要,如果你不知道在哪裏焦點當前位於調用此對多個文本字段;我沒有測試過這種情況。
此外,在界面生成器,你將需要啓用該視圖的「已啓用用戶交互」複選框,或編程使用:
myView.userInteractionEnabled = YES;
重複的: - - - - - - - - 這只是在搜索結果的第一頁... –
2009-09-10 22:54:06
恐怕你錯了,因爲他們都在談論當鍵盤不是數字類型,我知道如何禁用鍵盤,當它不是數字,不同的情況下,當你不得不消失「數字鍵盤」。在提出這個問題之前我搜索一下。 – itsaboutcode 2009-09-10 22:58:35
一旦用戶輸入號碼,您可以輕鬆地在屏幕上放置一個按鈕以關閉鍵盤。這不是電話應用程序的工作原理嗎?或者你可以在鍵盤上方放一個工具欄,上面有一個「don」按鈕,或者任意數量的東西(在x秒不活動後自動關閉鍵盤,一旦字段中的文本確認等等) – 2009-09-10 23:11:57