Я пытаюсь сделать удобную привязку клавиатуры к функции uiview.Я не могу найти эту ошибку
*** Завершение работы приложения из-за необработанного исключения 'NSInvalidArgumentException', причина: '- [Twitter.LoginVC handleKeyboard:]: нераспознанный селектор отправлен в экземпляр 0x7ffbf142e970'
class KeyboardService {
var constraint: NSLayoutConstraint!
var vc: UIViewController!
func bind(bottomConstraint: NSLayoutConstraint, vc: UIViewController) {
constraint = bottomConstraint
self.vc = vc
NotificationService.instance.addKeyboardObservers(onVC: vc, handleKeyboardSelector: #selector(self.handleKeyboard(_:))) // **CRASHES HERE**
}
@objc func handleKeyboard(_ notification: NSNotification) {
NotificationService.instance.handleKeyboard(notification: notification, bottomConstraint: constraint, vc: vc)
}
}
Вот мое уведомлениеСервис:
class NotificationService {
static let instance = NotificationService()
func addKeyboardObservers(onVC vc: UIViewController, handleKeyboardSelector: Selector) {
NotificationCenter.default.addObserver(vc, selector: handleKeyboardSelector, name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(vc, selector: handleKeyboardSelector, name: UIResponder.keyboardWillHideNotification, object: nil)
}
}
РЕДАКТИРОВАТЬ:
class KeyboardService {
var constraint: NSLayoutConstraint!
var vc: UIViewController!
func bind(bottomConstraint: NSLayoutConstraint, vc: UIViewController) {
constraint = bottomConstraint
self.vc = vc
NotificationService.instance.addKeyboardObservers(self, handleKeyboardSelector: #selector(self.handleKeyboard(_:)))
}
@objc func handleKeyboard(_ notification: NSNotification) {
NotificationService.instance.handleKeyboard(notification: notification, bottomConstraint: constraint, vc: vc)
}
}
РЕДАКТИРОВАТЬ 2:
class KeyboardService {
var constraint: NSLayoutConstraint!
var vc: UIViewController!
func bind(bottomConstraint: NSLayoutConstraint, vc: UIViewController) {
constraint = bottomConstraint
self.vc = vc
NotificationService.instance.addKeyboardObservers(self, handleKeyboardSelector: #selector(handleKeyboard(_:)))
}
@objc func handleKeyboard(_ notification: NSNotification) {
NotificationService.instance.handleKeyboard(notification: notification, bottomConstraint: constraint, vc: vc)
}
}
В viewDidLoad () виртуального канала:
KeyboardService().bind(bottomConstraint: loginBtnBackViewBottomConstraint, vc: self)