21

I have updated my project to Xcode 13 and iOS 15. Now the app is crashing with an error related to autoresizing masks in UITableViewCells. I have tried to change UITableViewCells Layer property in the inspector to Inferred and followed this post, but none of them are working.

Have you encountered this problem. How it could be fixed?

Here is some information about the error:

Error Image

Interface Builder Config Image

override func awakeFromNib() {
    super.awakeFromNib()
    selectionStyle = .none
    setupEventAction()
    configureAccessibilityForCellItem()
}

override func prepareForReuse() {
    super.prepareForReuse()
    eventView.eventImageView.image = nil
}

func configureAnnouncement(announcement: AnnouncementsRowItem, isWhiteCell: Bool = false) {
    eventView.isHidden = announcement.event == nil
    eventView.backgroundView.backgroundColor = isWhiteCell ? R.color.basic1_bg() : R.color.basic2_bg()
    if announcement.event?.eventID.isEmpty ?? false || !isWhiteCell {
        self.backgroundColor = R.color.basic2_bg()
    }
    bubbleView.configureAnnouncementsBubbleView(announcement: announcement)
    eventView.configureAnnouncementsEventView(announcement: announcement)
    layoutIfNeeded()
}

private func setupEventAction() {
    eventView.isUserInteractionEnabled = true
    let gesture = UITapGestureRecognizer(target: self, action: #selector(showEvent))
    gesture.numberOfTapsRequired = 1
    eventView.addGestureRecognizer(gesture)
}

@objc
func showEvent() {
    openEventClicked?()
}

Thanks

conradomateu
  • 213
  • 2
  • 7

7 Answers7

21

I have faced up with same problem. Try following: Open *.xib of your UITableViewCell as source code (Context menu / "Open As" / "Source Code"). Locate "tableViewCell" and "tableViewCellContentView" tags, delete its "translatesAutoresizingMaskIntoConstraints" attributes (with values), delete its subtags "autoresizingMask" if present.

https://i.stack.imgur.com/bDSJ3.png

overall63
  • 234
  • 2
  • 4
9

I think this has something to do with Xcode 13 and that too specifically for cells in xib file. For me it first time crashed on Xcode 13.2.1. Previously I used several versions of Xcode 12 and it never crashed.

The Content View of my cell in xib was already set to Autoresizing Mask but for the cell itself, the layout was set to Inferred(Constraints). So I changed that to Autoresizing Mask and stopped crashing.

  1. Set Content View layout to Autoresizing Mask enter image description here

  2. Set Cell layout to Autoresizing Mask enter image description here

HAK
  • 2,023
  • 19
  • 26
7

My issue was resolved with a different solution, while the error was the same the cause was different. A view inside my cell was assigned the same class from the cell, by removing the class the error was resolved. View inside TableViewCell with same class as TableViewCell

Javier Heisecke
  • 1,162
  • 1
  • 11
  • 28
3

Same thing happened to me with xCode 13.0 on iOS 15 only (previous iOS versions didn't have any issues).

To solve the problem, make sure your cell Content View is set to Layout: Autoresizing Mask (and not Inferred (Constrains)) under the size inspector as shown in the following image: Autoresizing Mask

Adir Kol
  • 349
  • 2
  • 4
1

Removing "translatesAutoresizingMaskIntoConstraints" for "tableViewCell" worked for me, but "autoresizingMask" stayed there as they were added by XCode automatically again.

1
  1. Change the Layout for TableViewCell and ContentView to "Autoresizing Mask". If it is still checked try changing to "Inferred Constraints" and back to "Autoresizing Mask".

  2. Try opening the xib file in the latest Xcode , save the changes performed by the Xcode and run again.

  3. Important - Check if tableView cell name and name of the child view inside the cell are not the same. Since the child view has the same name but layout settings is different app will crash. ( Older Xcode version worked properly on this scenario ).

Issue is reproducible on Xcode 13.1/13.2 and iOS 15.*

Ankit J
  • 204
  • 2
  • 10
  • 1
    I wonder why 3 would be the case. Thanks for the answer. It saved me hours of pulling my hair wondering why it wouldn't work. – funct7 Feb 24 '22 at 10:58
  • Human errors and old Xcode allowing duplicates names within same hierarchy. But Xcode-13.2 crashes and gives the same error for the 3rd case. – Ankit J Feb 25 '22 at 07:57
1

Also happens if you insert a UITableViewCell within your UITableViewCell. I was loading a custom view which I didn't realise was a UITableViewCell - for some reason I thought it was just a regular UIView.

JCutting8
  • 732
  • 9
  • 29