我有以下代码
lazy private var _containerView: UIView = {
let view = UIView(frame: self.view.frame)
let tapGesture = UITapGestureRecognizer(
target: self,
action: Selector(("didtapContainerView:"))
)
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = UIColor(white: 0.0, alpha: 0)
view.addGestureRecognizer(tapGesture)
tapGesture.delegate = self
return view
}()
这是方法
@objc final func didtapContainerView(gesture: UITapGestureRecognizer) {
setDrawerState(state: .Closed, animated: true)
}
我收到此错误
Forsa.KYDrawerController didtapContainerView]:无法识别的选择器已发送到实例
答案 0 :(得分:2)
您不知道如何为该方法选择正确的选择器。 (应该是"didtapContainerViewWithGesture:"
,但显然您不知道。)
所以不要尝试。使用#selector
语法,让编译器为您形成选择器!
只需说#selector(didtapContainerView)
。做完了
答案 1 :(得分:0)
这是Swift,将选择器更正为此
let tapGesture = UITapGestureRecognizer(target: self,action: #selector(didtapContainerView(_:)))
//
@objc func didtapContainerView(_ gesture: UITapGestureRecognizer) {
setDrawerState(state: .Closed, animated: true)
}