UIGestureRecognizer 添加手势后造成 tableView 的 didSelectRow 无效解决方案
实现gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch)
方法
class Base_TVC: UITableViewCell {
var indexPath = IndexPath(row: 0, section: 0)
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
override func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return NSStringFromClass(touch.view!.classForCoder) != "UITableViewCellContentView"
}
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
self.preservesSuperviewLayoutMargins = false
self.separatorInset = .zero
self.layoutMargins = .zero
let tapGr = UITapGestureRecognizer.init(target: self, action: #selector(userTapped))
tapGr.delegate = self
self.addGestureRecognizer(tapGr)
addSubviews()
initUI()
configLogic()
}
func userTapped() {
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func addSubviews() {}
func initUI() {}
func configLogic() {}
}