簡體   English   中英

iOS 8無法從UITextField關閉鍵盤

[英]IOS 8 can't dismiss keyboard from UITextField

我相信我的問題類似於: 關閉模態視圖控制器后,iOS 8 Keyboard Dismissed延遲,但我不清楚其他線程如何在我的應用程序中解決該問題。

在Xcode5 / IOS7中,我顯示了一個帶有2個UITextFields的UIAlertView。 用戶可以簡單地按OK並繼續,也可以在文本字段中輸入密碼/確認密碼。 在IOS7中,當我顯示Alertview時,我隱藏了鍵盤,如果/當用戶點擊文本字段時,鍵盤會自動重新出現:

UIAlertView *startTurnAlert;
UITextField *textField0, *textField1;
startTurnAlert = [[UIAlertView alloc]
                      initWithTitle:[NSString stringWithFormat:@"Player %d, Begin Turn %d",playerNumber, turnNumber]
                      message:[NSString stringWithFormat:@"%@, report for duty!", playerNames[playerNumber] ]
                      delegate:self
                      cancelButtonTitle:@"Exit Game"
                      otherButtonTitles:@"OK",
                                        nil
                      ];
startTurnAlert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

textField0 = [startTurnAlert textFieldAtIndex:0];
textField0.secureTextEntry = YES;
textField0.keyboardType = UIKeyboardTypeDefault;
textField0.placeholder = @"Enter a passcode (optional)";

textField1 = [startTurnAlert textFieldAtIndex:1];
textField1.placeholder = @"Re-enter passcode";
textField0.keyboardType = UIKeyboardTypeDefault;

[startTurnAlert show];
[textField0 endEditing:YES];
[textField1 endEditing:YES];

在更新到Xcode 6並構建為IOS8后,無需更改代碼,鍵盤就不會隱藏。 我嘗試添加resignFirstResponder這樣,沒有運氣:

[startTurnAlert show];
[textField0 resignFirstResponder];
[textField0 endEditing:YES];
[textField1 resignFirstResponder];
[textField1 endEditing:YES];

因此,在IOS8中,如何隱藏隱藏在UIAlertview中的UItextField的鍵盤, 直到用戶實際上通過點擊文本字段指示輸入文本的意圖?

謝謝!

我也遇到了同樣的問題,試圖隱藏模式彈出窗口中的鍵盤。 resignFirstResponder將什么都不做。

解決方案...是禁用對話框中的所有UITextFields控件(以便iOS無法鎖定需要鍵盤的任何控件),然后在一秒鍾之內重新啟用相關的控件。

這很煩人,但是有效...

(嘆。)

我不確定是否有人像我一樣遇到iOS9的相同問題,但是我設法通過以下方式使其正常工作:

  1. 嘗試專注於文本字段之一

     [self.someTextfield becomeFirstResponder]; 
  2. 然后延遲它,然后移開焦點

     double delayInSeconds = 0.5; // set the time dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [self.someTextfield resignFirstResponder]; }); 

由於它在iOS 7中有效,並且您已經花了一段時間,因此我將在此處找到的問題中實現類似於第二個代碼塊的內容,起始於if [uialertcontroller class]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM