Reputation: 55
I watched this video on a Messaging App for Swift and copied it word for word. Yet, there have been some updates to Xcode recently so I am not sure if that is the problem or I typed something in wrong. I also looked at other questions similar to mine and still can't find the issue.
The code I putting in the viewDidLoad() deals with the showing the keyboard:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown", name: UIKeyboardDidShowNotification, object: nil)
Then I call the keyboardWasShow function here:
func keyboardWasShown(notification: NSNotification) {
let dict : NSDictionary = notification.userInfo!
let s : NSValue = dict.valueForKey(UIKeyboardFrameEndUserInfoKey) as! NSValue
let rect : CGRect = s.CGRectValue()
UIView.animateWithDuration(0.3, delay: 0, options: .CurveLinear, animations: {
self.resultsScrollView.frame.origin.y = self.scrollViewOriginalY - rect.height
self.frameMessageView.frame.origin.y = self.frameMessageOriginalY - rect.height
var bottomOffset : CGPoint = CGPointMake(0, self.resultsScrollView.contentSize.height - self.resultsScrollView.bounds.size.height)
self.resultsScrollView.setContentOffset(bottomOffset, animated: false)
}, completion: {
(finished: Bool) in
//
})
}
The reason why I think it's the keyboardWasShown function because output showed keyboardWasShown]: unrecognized selector sent to instance 0x7f848c12be40
Any help would be appreciated!
Upvotes: 0
Views: 3454
Reputation: 104092
The method you implemented takes an argument so you need to add a colon to the end of the selector name.
let center = NSNotificationCenter.defaultCenter()
center.addObserver(self,
selector: "keyboardWasShown:",
name: UIKeyboardDidShowNotification,
object: nil)
Upvotes: 10