【问题标题】:Why doesn't UIButton showsTouchWhenHighlighted work when the button is on a UITableViewCell?当按钮位于 UITableViewCell 上时,为什么 UIButton showsTouchWhenHighlighted 不起作用?
【发布时间】:2013-02-07 17:04:50
【问题描述】:

我将UIButton 放在UITableViewCell 上,并将其showsTouchWhenHighlighted 属性设置为YES。单元格的选择样式为UITableViewCellSelectionStyleNone。我有一个选择器,当点击按钮并且工作正常时,它会被调用,因此按钮可以正常获取触摸事件。但是,按钮在触摸时不显示高亮效果。

当我将此按钮放在UIView 上时,高亮效果会起作用。

当按钮放在单元格上时,我怎样才能使它工作?

【问题讨论】:

    标签: iphone ios uitableview uibutton touch


    【解决方案1】:

    您是将按钮添加到单元格还是 cell.contentView? contentView 属性的行为更像是一个常规的 UIView,这可能会解决您的问题。

    【讨论】:

    • 是的,我正在将它添加到 contentView。
    【解决方案2】:

    您需要在 Table View 上将 'delaysContentTouches' 设置为 NO

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-14
      • 2020-08-17
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      • 2011-09-17
      • 2016-07-06
      • 1970-01-01
      相关资源
      最近更新 更多