【问题标题】:Tap gesture not detected in UITableViewCell在 UITableViewCell 中未检测到点击手势
【发布时间】:2015-10-12 21:08:47
【问题描述】:

我正在尝试检测 UITableViewCell 内的 UIImageView 上的点击手势。

这是cellForRowAtIndexPath里面的部分代码:

let cell1 : cellTableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! cellTableViewCell


        tableView.allowsSelection = false
        cell1.profileImg.userInteractionEnabled = true

        let tappedOnImage = UIGestureRecognizer(target: cell1, action: "tappedOnImage:")

        cell1.profileImg.tag = indexPath.row
        cell1.profileImg.addGestureRecognizer(tappedOnImage)

这是处理手势的函数:

func tappedOnImage(sender:UITapGestureRecognizer){


    print("hey")
}

但是,当我点击时,什么都没有发生。有什么建议吗?

【问题讨论】:

    标签: ios swift uitableview uigesturerecognizer uitapgesturerecognizer


    【解决方案1】:

    如果不查看更多代码,很难判断出什么问题,但试试这个:

    let tappedOnImage = UITapGestureRecognizer(target: self, action: "tappedOnImage:")
    

    【讨论】:

    • 除非你的 tappedOnImage 函数在类 cellTableViewCell 中实现。如果是这种情况,那么我会尝试在该类中添加手势识别器,而不是在 cellForRowAtIndexPath 所在的位置。
    • 是的,一切都在 cellForRowAtIndexPath 中
    • UIGestureRecognizer 是一个抽象类。在你的 cellForRowAtIndexPath 方法中使用 UITapGestureRecognizer
    猜你喜欢
    • 2018-12-18
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    • 2019-10-24
    • 2016-09-13
    • 1970-01-01
    相关资源
    最近更新 更多