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

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

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

Swift 2は、Apple社が独自に開発を行っている言語「Swift」のアップグレード版です。iOSやOS X、さらにLinuxにも対応可能です。また、throws-catchベースのエラーハンドリングが追加されています。

Q&A

解決済

1回答

1886閲覧

swift3 エラー

hirotoshin

総合スコア24

Swift 2

Swift 2は、Apple社が独自に開発を行っている言語「Swift」のアップグレード版です。iOSやOS X、さらにLinuxにも対応可能です。また、throws-catchベースのエラーハンドリングが追加されています。

0グッド

0クリップ

投稿2016/11/02 17:53

xcodeをアップデートしてswift2からswift3にしたところ下記のコードでエラーが出てしまいます。
エラー名はtype "viewcontroller" has no member "handleKeyboardWillShowNotification"です。
archiveの時にエラーが出たためアップデートをすればなんとかなるかなと思ったのですが...
なんだか余計にわからなくなりました...

swift3

1 override func viewWillAppear(_ animated: Bool) { 2 super.viewWillAppear(animated) 3 4 let notificationCenter = NotificationCenter.default 5 notificationCenter.addObserver(self, selector: #selector(ViewController2.handleKeyboardWillShowNotification(_:)), name: UIKeyboardWillShowNotification, object: nil) 6 notificationCenter.addObserver(self, selector: #selector(ViewController2.handleKeyboardWillHideNotification(_:)), name: UIKeyboardWillHideNotification, object: nil) 7 } 8

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

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

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

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

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

guest

回答1

0

ベストアンサー

Swift3では以下のようになります、参考にしてください。

swift

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

投稿2016/11/02 21:06

_Kentarou

総合スコア8490

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

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

hirotoshin

2016/11/03 09:57

ありがとうございます。解決しました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問