【问题标题】:iOS 13 beta UITableViewCell Child View Touch Selects Table View CelliOS 13 beta UITableViewCell 子视图触摸选择表格视图单元格
【发布时间】:2020-01-01 22:28:36
【问题描述】:

所以我有一个 UITableView 和一个自定义 UITableViewCell,它有自己的自定义子视图。

在 iOS 12 中,上面的自定义子视图可以被触摸,它不会选择整个 Table View Cell。

在 iOS 13 Beta 中,触摸自定义子视图也会突出显示/选择整个表格视图单元格。

    final class myTableView: UITableViewController {
      .......
        override final func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
      {

        //Do things for table view cell selection

      }
      .......
    }


    final class CustomChildView : UIView {
     ........
      override final func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
      {
            super.touchesBegan(touches, with: event)
            //Do touch down things

      }
     ........
    }

有没有办法在自定义子项被触摸时取消表格视图单元格的选择?

【问题讨论】:

    标签: ios xcode uitableview uiview uitouch


    【解决方案1】:
        final class CustomChildView : UIButton {
     ........
      override final func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
      {
            super.touchesBegan(touches, with: event)
            //Do touch down things
    
      }
     ........
    }
    

    将 UIView 更改为 UIButton,现在它可以正常工作了。

    【讨论】:

      【解决方案2】:

      您的问题是 view 会自动将选择传递给 parent好吧。
      您需要做的是覆盖 child custom viewsetSelected 函数,这样它就不会将选择传播到 UI 树。

      override func setSelected(selected: Bool, animated: Bool) {
          // Add here code to not select parent
      }
      

      在 Reinder 的 Blog 中,您有 6 种不同的方法(其中一些是众所周知的设计模式)在 view controllers 之间传递数据,包括使用 propertiesseguesNSNotificationCenter >

      【讨论】:

      • 是否可以从子类的“子自定义视图”中引用父表视图?
      • @Gizmodo 请查看:learnappmaking.com/…
      • 我将自定义子视图从 UIView 更改为 UIButton。现在它按预期工作。我猜 UIButton 会以某种方式阻止触摸以某种方式向上移动。
      猜你喜欢
      • 1970-01-01
      • 2019-05-22
      • 2011-10-08
      • 1970-01-01
      • 2012-07-20
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 2015-03-07
      相关资源
      最近更新 更多