gpt4 book ai didi

ios - UITableViewCell : UITapGestureRecognizer unrecognized selector sent to instance error

转载 作者:行者123 更新时间:2023-11-30 13:43:39 25 4
gpt4 key购买 nike

我在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com