プログラミング初心者です。
ScrollViewの上に、TextFieldを設置し、タップすると、TextFieldがキーボードに隠れないようにの高さ調整するための実装をし、特にエラー表示もなかったのでビルドし、該当のTextFieldをシュミレーターでタップしたところ、下記のようなエラーが表示されました。
こちらの解決方法がわからないため、ご教示いただけると幸いです。
なお事前に、以下の類似のエラーかと思いIBOutletやプロパティ名を付け直したりしましたが、エラーは解消しませんでした。
https://qiita.com/ruwatana/items/7cfc63ce102938962260
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fbtest.LoginViewController handleKeyboardWillShowNotification:]: unrecognized selector sent to instance 0x786611b0'
swift3.0
1import UIKit 2import Firebase 3 4class LoginViewController: UIViewController, UITextFieldDelegate, UIScrollViewDelegate { 5 6 7 @IBOutlet weak var loginScrollView: UIScrollView! 8 9 @IBOutlet weak var emailTextField: UITextField! 10 11 @IBOutlet weak var passwordTextField: UITextField! 12 13 14 var txtActiveField = UITextField() 15 16 override func viewDidLoad() { 17 super.viewDidLoad() 18 emailTextField.delegate = self 19 passwordTextField.delegate = self 20 self.title = "ログイン" 21 22 } 23 24 override func didReceiveMemoryWarning() { 25 super.didReceiveMemoryWarning() 26 } 27 28 //Keyboard以外をタッチで編集を終了 29 override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 30 self.view.endEditing(true) 31 } 32 33 //リターンキーを押すと編集を終了 34 func textFieldShouldReturn(_ textField: UITextField) -> Bool { 35 textField.resignFirstResponder() 36 return true 37 } 38 39 //テキストフィールド編集開始/終了時の処理 40 func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool { 41 txtActiveField = textField 42 return true 43 } 44 45 func textFieldShouldClear(_ textField: UITextField) -> Bool { 46 self.view.endEditing(true) 47 return true 48 } 49 50 51 //keyboardを押した時の高さを取得しスクロールする処理 52 func handleKeyboardWillShowNotification(notification: NSNotification) { 53 54 let userInfo = notification.userInfo! 55 let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue 56 let myBoundSize: CGSize = UIScreen.main.bounds.size 57 58 let txtLimit = txtActiveField.frame.origin.y + txtActiveField.frame.height + 8.0 59 let kbdLimit = myBoundSize.height - keyboardScreenEndFrame.size.height 60 61 print("テキストフィールドの下辺:(txtLimit)") 62 print("キーボードの上辺:(kbdLimit)") 63 64 if txtLimit >= kbdLimit { 65 loginScrollView.contentOffset.y = txtLimit - kbdLimit 66 } 67 } 68 69 //keyboardを閉じるときに高さを元に戻す処理 70 func handleKeyboardWillHideNotification(notification: NSNotification) { 71 loginScrollView.contentOffset.y = 0 72 } 73 74 //UITextFieldの下辺とキーボードの上辺が重なっているかどうか調べるための処理 75 //NotificationCenterの設定周り 76 override func viewWillAppear(_ animated: Bool) { 77 super.viewWillAppear(animated) 78 79 let notificationCenter = NotificationCenter.default 80 notificationCenter.addObserver(self, selector: Selector(("handleKeyboardWillShowNotification:")), name: NSNotification.Name.UIKeyboardWillShow, object: nil) 81 notificationCenter.addObserver(self, selector: Selector(("handleKeyboardWillHideNotification:")), name: NSNotification.Name.UIKeyboardWillHide, object: nil) 82 } 83 84 override func viewDidDisappear(_ animated: Bool) { 85 super.viewDidDisappear(animated) 86 87 let notificationCenter = NotificationCenter.default 88 notificationCenter.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil) 89 notificationCenter.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil) 90 } 91
どうぞよろしくお願いいたします。
(deleted)
回答1件
あなたの回答
tips
プレビュー