【问题标题】:UILable above the UITableVIew, UILable can not touch, why?UILabel上面的UITableVIew,UILabel不能触摸,为什么?
【发布时间】:2018-11-29 02:09:02
【问题描述】:

UITableVIew上面有个UILable,UILable和UITableVIew是兄弟,我在UILable里面加了GestureRecognizer,但是这个手势不能触发,为什么?

【问题讨论】:

  • 您是否将标签的userInteractionEnabled 属性设置为true
  • 将 userInteractionEnabled 设置为 true
  • @AndréSlotta,感谢您的帮助,我已将 userInteractionEnabled 设置为 true ,我猜 UiLable 的交互与 tableView 的交互冲突,但我不知道为什么
  • @AneeshG,感谢您的帮助,我已将 userInteractionEnabled 设置为 true
  • @mrX 快乐编码

标签: ios uitableview uilabel


【解决方案1】:

确保将 userInteractionEnabled 设置为 true

在你看来DidLoad

    YOUR_Label.isUserInteractionEnabled = true
    let tap = UITapGestureRecognizer(target: self, action: #selector(self.uilabelTapped(_:)))
    YOUR_Label.addGestureRecognizer(tap)

在您的 ViewController 中

@objc func uilabelTapped(_ sender: UITapGestureRecognizer) {
    print("UILabel Tapped")
}

确保您的 tableView 和 uilabel 是同一视图的子视图

希望对你有帮助

【讨论】:

  • 感谢您的帮助,我已将 userInteractionEnabled 设置为 true ,我猜 UiLable 的交互与 tableView 的交互冲突,但我不知道为什么
猜你喜欢
  • 2013-04-12
  • 1970-01-01
  • 2011-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-29
  • 1970-01-01
相关资源
最近更新 更多