iOS 13 beta UITableViewCell Child View Touch Selects Table View Cell

1.1k Views Asked by At

So I have a UITableView with a custom UITableViewCell which has its own custom child view.

enter image description here

In iOS 12, above custom child view could be touched, it would not select the whole Table View Cell.

In iOS 13 Beta, touching custom child view also highlights/selects the whole Table View Cell.

    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

      }
     ........
    }

Is there a way to cancel table view cell selection when the custom child is touched?

2

There are 2 best solutions below

3
GingerHead On

Your problem is that the view is automatically passing the selection to the parent as well.
What you need to do is override the setSelected function of the child custom view so that it would not propagate the selection to the upper nodes of the UI tree.

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

In Reinder's Blog, you have 6 different methods (some of them well known design patterns) of passing data between view controllers, including working with properties, segues and NSNotificationCenter

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

  }
 ........
}

Changed UIView to UIButton, and now it works as intended.