I'm trying to scroll the view (to prevent the keyboard from hiding text fields), but I can't seem to get the keyboard notification to function properly.
This code is based on Apple's documentation (see here).
First, we add the listener in the viewDidLoad()
of a UIViewController
subclass.
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWasShown"), name: UIKeyboardDidShowNotification, object: nil)
When the event fires, it crashes immediately with the unrecognized selector
error message, and won't even print to the console:
func keyboardWasShown(notification: NSNotification) {
println("Keyboard will be SHOWN")
}
But without the parameter, I get "Keyboard will be SHOWN" in the console.
func keyboardWasShown() {
println("Keyboard will be SHOWN")
}
What am I doing wrong?