Hiding keyboard breaks segue of TableView

时间:2016-04-04 18:41:57

标签: ios swift

let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(Viewcontroller.dismissKeyboard))
            view.addGestureRecognizer(tap)

    func dismissKeyboard() {
            view.endEditing(true)
        }

My code that hides keyboard.

But this code also breaks segue of TableView.

Is there any other way to hide keyboard by touching somewhere of the view?

1 个答案:

答案 0 :(得分:0)

如果你确定你的轻拍手势识别器工作正常。您应该使用textField的resignFirstResponder方法。想想这一点,如果用户点击你的textField键盘会显示,以及他们是否在视图中的某个地方点击了textView的外部。应使用texfield.resignFirstResponder()方法触发TapGestureRecognizer。所以你的键盘应该是隐藏的。

如果它不起作用。请使用print 测试您的 tapGestureRecognizer 方法。

相关问题