前提・実現したいこと
開発環境:iMac OS:High Siera
xcode:9.1
言語:Objective-C
実行環境:iPad Pro
OS:ios11
古いObjective-Cのソースをios11に対応するため、プログラムの改修を行っています。
ユーザID/パスワードを求めるUIAlertViewを表示して、パスワードエラーの場合、エラーのUIAlertを表示して、再度パスワード入力のUIAlertViewを表示させる処理があるのですが、
パスワード入力画面表示
↓(エラーのパスワード入力し、実行をタップ)
キーボード画面が隠れる
↓
パスワードエラー画面表示&
キーボード画面が現れる。
となります。(キーボード画面にはテキスト入力の箇所はありません)
色々情報を調べると、UIAlertControllerに移行すべきという例が載っており、
Objective
1コード 2- (void)showPasswordAlertView{ 3 UIAlertController *alert = 4 [UIAlertController alertControllerWithTitle:@"パスワード入力" 5 message:@"パスワードを入力後、\n「実行」をタップしてください。" 6 preferredStyle:UIAlertControllerStyleAlert]; 7 8 [alert addAction:[UIAlertAction actionWithTitle:@"キャンセル" 9 style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 10 NSLog(@"Cancel"); 11 } ]]; 12 13 [alert addAction:[UIAlertAction actionWithTitle:@"実行" 14 style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 15 // 認証処理 16 : 17 if ( auth == 0 ) { 18 //認証失敗 19 error = YES; 20 } else { 21 // 認証成功 22 error = NO; 23 } 24 [self judgeWorkerPassword:error]; 25 } ]]; 26 27 [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) { 28 textField.delegate = self; 29 }]; 30 [self presentViewController:alert animated:YES completion:nil]; 31 32} 33 34-(void)textFieldDidEndEditiong:(UITextField *)textField { 35 self.password = textField.text; 36} 37 38- (void)judgeWorkerPassword:(BOOL)error{ 39 40 if(error == YES){ 41 //エラー 42 UIAlertController *alert = 43 [UIAlertController alertControllerWithTitle:@"パスワードエラー" 44 message:@"入力したパスワードが間違っています。" 45 preferredStyle:UIAlertControllerStyleAlert]; 46 [alert addAction:[UIAlertAction actionWithTitle:@"確認" 47 style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { 48 // ボタンが押された時の処理 49 [self showPasswordAlertView]; 50 }]]; 51 52 [self presentViewController:alert animated:YES completion:^{ 53 // 表示完了時の処理 54 }]; 55 } 56 else{ 57 //OK 58 [self.delegate HSWorkerListViewController:self wkData:self.selectedWorker mode:mode]; 59 } 60} 61
と実装してみたのですが、
パスワード入力画面表示
↓(エラーのパスワード入力し、実行をタップ)
キーボード画面が隠れる
↓
パスワードエラー画面表示
↓
キーボード画面が現れる。
↓
キーボード画面が自動的に隠れる。
となり、一瞬キーボードが表示されてしまいます。
パスワードエラー画面表示の際に、キーボードを表示しないようにするにはどのようにしたら良いでしょうか?
わかる方がいらっしゃいましたら、ご回答をお願いします。
#補足ですが、エラーにならずにほかの画面に移動した場合も同様にキーボードが一瞬表示されるようです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。