22

On an iOS 14 device compiled with XCode 12 an extra UITableViewCellContentView is appearing above the content of the table view preventing any of the buttons underneath it from being tapped. This only appears in iOS 14. It does not appear in iOS 13. Any ideas on how to remove it? enter image description here

Ravi Damani
  • 296
  • 2
  • 6

7 Answers7

15

You have to add your views to cell contentView like this:

contentView.addSubview(button)

and anchor your button to contentView:

button.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
tornic
  • 747
  • 6
  • 15
  • This is done. And your response implies that the problem will happen on all iOS 10+ but the issue presents itself only on iOS 14. – Ravi Damani Sep 19 '20 at 01:53
  • I had the same problem, and adding the subview on contentView instead of view worked for me. However, the code you added about the anchor makes no sense here. @RaviDamani why do you say it implies that the problem would happen from iOS 10+? – nikano Sep 24 '20 at 11:19
  • 1
    Sorry, you are absolutely correct. Your code fixed it! – Ravi Damani Sep 26 '20 at 00:48
7

If your project is big and it's hard to change every addSubview to contentView.addSubview, you can add this extension to your project:

extension UITableViewCell {
    open override func addSubview(_ view: UIView) {
        super.addSubview(view)
        sendSubviewToBack(contentView)
    }
}
Ayan Kurmanbay
  • 119
  • 2
  • 2
1

Had the same issue, we did this :

sendSubviewToBack(contentView)
Guillaume Ramey
  • 205
  • 2
  • 5
0

I had this same issue, although I'm not sure my solution will work for you or not. My issue was caused by the UISearchControllerDelegate method presentSearchController being called twice in iOS14. When this method was called, we superimposed a new "containerView" onto our current View and displayed our search results. when didDismissSearchController is called we removed this view. The problem is that presentSearchController was being called twice, which created two "containerViews". we would remove one of them but the other one stuck around and intercepted all of our touches. We just needed to make sure not to add two "containerViews".

Here is what we did

func presentSearchController(_ searchController: UISearchController) { 

   guard containerView == nil else {return}

   containerView = UIView()
   viewController.view.addSubview(containerView)

   //present search results

}

func didDismissSearchController(_ searchController: UISearchController) { 

   containerView.removeFromSuperview()
   containerView = nil

   //any other code you need

}
jameseronious
  • 219
  • 2
  • 5
0

I have faced this issue recently in iOS 14.5. May my fix helps to save others time.

Just enable clips to bounds for your cell in attribute manager or programmatically make this bool true. Now cell bottom extra view is not overlaid and appears.

Elavarasan K
  • 116
  • 3
0

you should set the tableview separator style to none. in my case, any other answers didn't work. Just set the separator style to none, then UITableViewCellContentView will be removed.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 10 '22 at 18:54
-3

Try this code

contentView.isUserInteractionEnabled = true