我有:
var swipe: UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "dismissKeyboard")
swipe.direction = UISwipeGestureRecognizerDirection.Down
self.view.addGestureRecognizer(swipe)
和
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
func dismissKeyboard() {
self.messageTextView.resignFirstResponder()
}
}
当我向下滑动设备时,我收到错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppName.ViewController dismissKeyboard]: unrecognized selector sent to instance 0x125d06500'
我的viewDidLoad中有很多其他代码,而我的messageTextView位于UITiew中,位于UITableView中。可能是什么问题呢?
答案 0 :(得分:0)
您的dismissKeyboard
方法嵌套在didReceiveMemoryWarning
方法中。这是错的。您必须将dismissKeyboard
方法声明为视图控制器的方法。然后它应该工作。
messageTextView
是否嵌入在表格视图中? UITableView
类已经提供了在滑动时关闭键盘的机会。你只需要像这样设置dismissMode
:
tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;