Reputation: 18523
My app sometimes crashes at the call to textView.becomeFirstResponder()
. The error thrown is strange:
-[UITextSelectionView keyboardShownWithNotif:]: unrecognized selector sent to instance 0x16899070
Sometimes it's:
-[UIImageView keyboardShownWithNotif:]: unrecognized selector sent to instance 0x178e2610
I did add notification listeners:
NotificationCenter.default.addObserver(self, selector: #selector(keyboardShown(notif:)), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardHidden), name: .UIKeyboardWillHide, object: nil)
But the observer is the custom view I defined, why does the system send notification to UITextSelectionView
or UIImageView
?
Found in iOS 8.4.1, not reproduced in iOS 9.
What is happening here?
Upvotes: 0
Views: 528
Reputation: 377
In swift 3:
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: self.view.window)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: self.view.window)
}
or
deinit {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: self.view.window)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: self.view.window)
}
Upvotes: 0
Reputation: 330
seems like you added an notif. observer to show/hide keyboard.
Try to remove observer in dealloc method
- (void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self]; //Or whichever observer you want to remove
}
Upvotes: 2