ios - UITableViewCell : UITapGestureRecognizer unrecognized selector sent to instance error

标签 ios swift uitableview

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

相关文章:

ios - 保存和读取登录到钥匙串(keychain)不工作 IOS swift

ios - 实现 searchBarSearchButtonClicked

ios - 解码子类时忽略父类(super class)属性

python - Postman Swift 代码显示与我的正常 url 不同的 url

ios - Core Data/UITableView 上的动画数据刷新(软删除)

swift - 数据未显示在 TableView Swift CoreData 中

ios - iOS的FCM静默推送通知结构?

javascript - 在 iOS8 Safari 中,只读输入处理不正确

swift - 从 compactMap 返回和退出

ios - UIView 中的 Swift TableView 不显示数据