我在UITableViewCell
中的UILabel
上有一个UITapGestureRecognizer
,我添加了所述UITapGestureRecognizer
的目标作为 View Controller ,如下所示:
class Cell: UITableViewCell {
@IBOutlet weak var label: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
let tap1 = UITapGestureRecognizer(target: ViewController(), action: "selectLabel:")
label.addGestureRecognizer(tap)
}
}
class ViewController: UIViewController,UITableViewDataSource, UITableViewDelegate{
fun selectLabel(gesture: UITapGestureRecognizer){
//animate some view in custom cell
}
}
但是,我收到“UITapGestureRecognizer 无法识别的选择器已发送到实例”错误。
最佳答案
在cellForRowAtIndexPath上设置手势。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellIdentifier", forIndexPath: indexPath) as! Cell
let tap1 = UITapGestureRecognizer(target: self, action: "selectLabel:")
cell.label.addGestureRecognizer(tap1)
return cell
}
关于ios - UITableViewCell : UITapGestureRecognizer unrecognized selector sent to instance error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35248204/