2

After updating my phone to iOS 14, I can no longer interact with content within UICollectionViewCell or within UITableViewCell for my app. The issue is also present in iOS simulators running iOS 14, but everything works fine with iOS 13 and below.

I have buttons and other collection views within the cells that are no longer interactable. It's as if the entire cell content has become static. Below is some code from my UICollectionViewCells and UICollectionViewController, however the same issue is present in UITableViewCells. I am using Swift 5. didSelectItemAt and similar functions work fine, it's interacting within the cell's contentView specifically that appears to not be working. I can paste more code if necessary as I trimmed some fluff and other code I have narrowed down to not be a problem.

Since the issue is present in both UICollectionViewCell and UITableViewCell I believe I am doing something wrong at a more fundamental level.

Relevant code from the UICollectionViewCell:

override init(frame: CGRect) {
    super.init(frame: frame)
    setupContainers()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

func setupContainers() {
    // Adding subviews like so...
    addSubview(subviewToAdd)

    // Anchor all subviews using NSConstraints
}

And then relevant code from the UICollectionViewController

override func viewDidLoad() {
    super.viewDidLoad()
    setStyleAndDelegates()
}

private func setStyleAndDelegates() {
    collectionView?.backgroundColor = UIColor.white

    collectionView?.delegate = self
    collectionView?.dataSource = self
    
    collectionView?.register(MyCell.self, forCellWithReuseIdentifier: eventCellId)
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: eventCellId, for: indexPath) as! MyCell
    return cell
}

EDIT: Upon further inspection of the view hierarchy, there is an additional UIView placed directly on top of all content in the cell in iOS 14. In iOS 13, this view is not there. Pictures attached below. iOS 13 as expected iOS 14 with additional view

Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93
Sanzio Angeli
  • 2,872
  • 1
  • 16
  • 30
  • The code you have posted is awfully generic, and you haven't provided much information about the components of your cells and what you are doing with them. The code you posted calls a `setupCellWithEvent()` method which you don't show. You do show part of the code for a UICollectionViewCell subclass, but that looks incomplete. (IF you're invoking it using `dequeueReusableCell(withReuseIdentifier: for:)`, its `init?(coder:)` method is going to be called, but you don't support that method. – Duncan C Sep 18 '20 at 18:49
  • Have you tried using the Xcode view debugging tool to see if there is something wrong with your view hierarchy? – Duncan C Sep 18 '20 at 18:50
  • I have added the `setupCellWithEvent` function in its entirety and will look into the debugging tool. Thank you! The `setupCellWithEvent` does not do anything to the properties of the cell itself but rather updates content of the cells subviews. I do invoke using `dequeueReusableCell`, however the `override init(frame: CGRect)` also gets called at some point because the cell has the corner radius and background color. – Sanzio Angeli Sep 18 '20 at 19:19
  • After inspecting the view hierarchy, there is an additional `UIView` placed directly on top of all content in the cell. This does not appear in iOS 13 (as shown in the pictures added to the question). The same thing happens in my table view cells. How would I go about finding how this view got there? – Sanzio Angeli Sep 18 '20 at 19:48
  • Thank you for the help, I figured it out with the view hierarchy and added the answer. I will also edit the question and paste only relevant code that is required to replicate the problem. – Sanzio Angeli Sep 18 '20 at 20:14
  • @SanzioAngeli This behavior is observed in app compiled against iOS 13 and working under iOS 14 ( after a device update ) or the app was recompiled with Xcode 12 ( iOS 14 SDK )? – Blazej SLEBODA Sep 18 '20 at 20:29
  • Compiled against iOS 13 and 14. The screenshots in the question were both from Xcode Version 12.0 but from two different device simulators (one simulator running iOS 13.5, and another running iOS 14, both iPhone 11) – Sanzio Angeli Sep 18 '20 at 20:35

1 Answers1

7

Thank you to @Duncan C for recommending taking a look at the view hierarchy.

Content was being added to cell simply by addSubview()

Instead, content should be added to the cell's contentView with contentView.addSubview(). This fixed the issue.

With my current setup, in iOS 13 and below content added simply with addSubview() appeared above the cell's contentView. This is better portrayed in the pictures shown in the question.

In iOS 14 and again with my current setup, this content was getting inserted below the cell's contentView, and as such the contentView was blocking user interaction to the rest of the content added directly to the cell.

Sanzio Angeli
  • 2,872
  • 1
  • 16
  • 30