數字鍵盤我有兩個文本字段一個是輸入用戶名和第二個是手機號碼如何隱藏在iphone
用戶名: 有可能對我來說,使用這個隱藏鍵盤的用戶名文本字段方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
我的問題是 手機號碼:
如何隱藏手機號碼文本字段的問題?
數字鍵盤我有兩個文本字段一個是輸入用戶名和第二個是手機號碼如何隱藏在iphone
用戶名: 有可能對我來說,使用這個隱藏鍵盤的用戶名文本字段方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
我的問題是 手機號碼:
如何隱藏手機號碼文本字段的問題?
使用
textField.keyboardType = UIKeyboardTypeNumberPad;
從給定的代碼判斷,顯然他想用回車鍵隱藏鍵盤,但數字鍵盤沒有返回鍵,因此是問題所在。 – Desdenova
您可以使用下面library添加完成和取消按鈕上的數字鍵盤。
你也可以使用點觸手勢來隱藏號碼pad.Use下面的代碼:
- (void)viewDidLoad
{
UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissKeyboard)];
tapGesture.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tapGesture];
}
-(void)dismissKeyboard
{
[textField resignFirstResponder];//Assuming that UITextField Object is textField
}
這將爲you..Happy編碼工作!乾杯..!!
有幾個選項對您開放,您需要決定何時關閉文本框數字鍵盤。舉例來說,如果你有個數字一組數字你你解僱之前需要你可以訂閱
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textFieldTextDidChange:) name:UITextFieldTextDidChangeNotification object:nil];
然後在實現沿
-(void)textFieldTextDidChange:(NSNotification *)notification
{
UITextField *textfield = notification.object;
if(textfield.text.length == NUMBER_OF_DIGITS_NEEDED)
[textField resignFirstResponder];
}
線的東西。如果你的用戶也需要能夠要自行決定關閉鍵盤,您應該在剩餘的可見視圖上放置一個輕擊手勢識別器。
UITapGestureRecognizer *tapGestureRecogniser = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGestureRecogniser.delegate = self;
[self.view addGestureRecognizer:tapGestureRecogniser];
-(void)handleTapGesture:(UITapGestureRecognizer *)tapGestureRecogniser
{
if ([self.myTextField isFirstResponder])
[self.myTextField resignFirstResponder];
}
- (void)viewDidLoad
{
[self addTapGesture];
}
#pragma mark
#pragma mark Gesture methods
- (void) addTapGesture {
UITapGestureRecognizer *tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
tapper.cancelsTouchesInView = FALSE;
[self.view addGestureRecognizer:tapper];
}
- (void)handleSingleTap:(UITapGestureRecognizer *) sender
{
[self.view endEditing:YES];
}
你應該採取這種[執行] [1] [1]:http://stackoverflow.com/questions/6991085/how-to-dismiss-number-pad -keyboard-by-tapping-anywhere –
http://stackoverflow.com/questions/584538/how-to-show-button-done-on-number-pad-on-iphone –
你能解釋一下你的更多信息嗎?想。 – Ayaz