質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

2回答

1621閲覧

Swift コードエラー

sweden1

総合スコア59

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2016/10/26 03:53

編集2016/10/26 03:55

###前提・実現したいこと
エラーを解決したい
###発生している問題・エラーメッセージ

thread1 signal SIGABRT

###該当のソースコード

Swift3

1 override func viewWillAppear(_ animated: Bool) { 2 super.viewWillAppear(animated) 3 4 let notificationCenter = NotificationCenter.default 5 notificationCenter.addObserver(self, selector: Selector(("handleKeyboardWillShowNotification:")), name: NSNotification.Name.UIKeyboardWillShow, object: nil) 6 notificationCenter.addObserver(self, selector: Selector(("handleKeyboardWillHideNotification:")), name: NSNotification.Name.UIKeyboardWillHide, object: nil) 7 } 8 9 override func viewDidDisappear(_ animated: Bool) { 10 super.viewDidDisappear(animated) 11 12 let notificationCenter = NotificationCenter.default 13 notificationCenter.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil) 14 notificationCenter.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil) 15 } 16

###試したこと
viewDidDisappear,viewWillappearを実行すると上記のエラーが出てきます
###補足情報
より詳細な情報
ここのサイト、githubを参考に練習しました。
URL
http://hayashi-rin.net/post-388
http://ameblo.jp/hayashidesuga/entry-11971210696.html

Github
https://github.com/hayashidesu/TextViewSample/blob/master/TextViewSample/ViewController.swift

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

以下のように変更して試してみてください。

swift

1override func viewWillAppear(_ animated: Bool) { 2 super.viewWillAppear(animated) 3 4 let notificationCenter = NotificationCenter.default 5 notificationCenter.addObserver( 6 self, 7 selector: #selector(self.handleKeyboardWillShowNotification(notification:)), 8 name: Notification.Name.UIKeyboardWillShow, 9 object: nil 10 ) 11 12 notificationCenter.addObserver( 13 self, 14 selector: #selector(self.handleKeyboardWillHideNotification(notification:)), 15 name: Notification.Name.UIKeyboardWillHide, 16 object: nil 17 ) 18} 19 20func handleKeyboardWillShowNotification(notification: NSNotification) { 21 print("handleKeyboardWillShowNotification") 22} 23 24func handleKeyboardWillHideNotification(notification: NSNotification) { 25 print("handleKeyboardWillHideNotification") 26}

投稿2016/10/26 04:36

編集2016/10/26 04:37
_Kentarou

総合スコア8490

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

sweden1

2016/10/26 08:26

func handleKeyboardWillShowNotification(notification: NSNotification) { let userInfo = notification.userInfo! let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue let myBoundSize: CGSize = UIScreen.main.bounds.size let txtLimit = txtActiveField.frame.origin.y + txtActiveField.frame.height + 8.0 let kbdLimit = myBoundSize.height - keyboardScreenEndFrame.size.height print("テキストフィールドの下辺:\(txtLimit)") print("キーボードの上辺:\(kbdLimit)") if txtLimit >= kbdLimit { textview.contentOffset.y = txtLimit - kbdLimit } } func handleKeyboardWillHideNotification(notification: NSNotification) { textview.contentOffset.y = 0 } func textFieldShouldBeginEditing(textField: UITextField!) -> Bool { txtActiveField = textField return true } func textFieldShouldReturn(textField: UITextField!) -> Bool { self.view.endEditing(true) return true } override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) let notificationCenter = NotificationCenter.default notificationCenter.addObserver(self, selector: Selector(("handleKeyboardWillShowNotification:")), name: NSNotification.Name.UIKeyboardWillShow, object: nil) notificationCenter.addObserver(self, selector: Selector(("handleKeyboardWillHideNotification:")), name: NSNotification.Name.UIKeyboardWillHide, object: nil) notificationCenter.addObserver( self, selector: #selector(self.handleKeyboardWillHideNotification(notification:)), name: Notification.Name.UIKeyboardWillHide, object: nil ) } Syntax エラーはないんですけどね。。。 やはりこれが出ます
sweden1

2016/10/26 08:27

ご返信していただけると幸いです
_Kentarou

2016/10/26 10:37

そもそもですがXcode, Swiftのバージョンはいくつになりますか?
guest

0

環境がないので試してもらうことになりますが、nameの指定のところを、

swift

1.UIKeyboardWillShow 2.UIKeyboardWillHide

と、ピリオド以下だけにするとどうなるでしょうか?

投稿2016/10/26 04:09

fuzzball

総合スコア16731

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問