Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build an Interactive Story App with Swift Personalizing the Story Communicating Via Notifications

Ingo Ngoyama
Ingo Ngoyama
4,882 Points

There is no keyboardWill Show choice.

on the inter active app when we are making the key board the IDE does not show keyboardWillShow as an option to ViewController. . Is this a Swift 3.1 thing. As a matter of fact a key board does not show up on my app at all. It takes text from my laptop keyboard.

Jeff McDivitt
Jeff McDivitt
23,970 Points

Do you have

import UIKit

in your file?

4 Answers

Jeff McDivitt
Jeff McDivitt
23,970 Points

And you have the functions written in your code

    func keyboardWillShow(_ notification: Notification) {
        if let info = notification.userInfo, let keyboardFrame = [UIKeyboardFrameEndUserInfoKey] as? NSValue {
            let frame = keyboardFrame.cgRectValue
            textFieldBottomConstraint.constant = frame.size.height + 10

            UIView.animate(withDuration: 0.8) {self.view.layoutIfNeeded()

            }
        }
    }

    func keyboardWillHide(_ notification: Notification){
        textFieldBottomConstraint.constant = 40

        UIView.animate(withDuration: 0.8) { self.view.layoutIfNeeded() }
    }

    deinit {
        NotificationCenter.default.removeObserver(self)
    }

}
Ingo Ngoyama
Ingo Ngoyama
4,882 Points

Where is this located? Pasan said it was the system that will automatically put keyboard in the APP and there was no object for it. So I figured for some reason mine did not because it is the new 3.1. On his video he seemed surprised that the keyboard showed up by itself. It may have been a glitch or feature in 3.0. So because he got it automatically he never showed this code.

Ingo Ngoyama
Ingo Ngoyama
4,882 Points

Pasan said to set my simulator. I posted how to do it.

Ingo Ngoyama
Ingo Ngoyama
4,882 Points

FOR ANY ONE ELSE WHO HAS THIS PROBLEM. Pasan let me know to go to the simulator and turn on the key board.

   go to simulator menu and :  hardware> simulator> keyboard> toggle software keyboard

(this is not code) This will make it display.

Thanks — the keyboard wasn't showing up in the simulator for me, either...

Ben Moore
Ben Moore
22,588 Points

Had the exact same issue. May be worth him adding a short cut-away clip or text on screen to notify students to look at a link to directions.

Xavier D
Xavier D
Courses Plus Student 5,840 Points

Alternately, the k keyboard command will work and avoid surfing thru the menus. You can also deselect the hardware keyboard option, but then that grays out software keyboard option.

Cancel this option in Simulator "Hardware>Keyboard>Connection HardWare Keyboard". the keyboard will show up !

Xavier D
PLUS
Xavier D
Courses Plus Student 5,840 Points

Hi

I think the k keyboard command while leaving Connection HardWare Keyboard enabled is better to display it because it can also make the keyboard not show if it's in the way. Canceling that connection hardware keyboard option grays out the option for the keyboard command.

XD