Search code examples
ios12ios13xcode11swift5

iOS 13 UITableViewCell | Child view gets clipped out


SO I have a UITableView which contains a UITableViewCell and tableView.header is set to a Parallax Header. The UITableViewCell has certain UIViews which are set as negative constraints from Top and are shown perfectly on iOS-12 whereas when observed on iOS-13 the UIViews showing over Parallax Header are clipped. I have tried all possible solutions but unfortunately it still shows the same. My App is opting out of SwiftUI and still running the old code. I have even tried to change the zIndex of the child UIView but still the same. Here are some snapshots and some code:

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code

    self.PriceView.layer.zPosition = 1
    self.PriceView.bringSubviewToFront(self.contentView)
    self.PriceView.setNeedsDisplay()
}

This code is functional for iOS-12 but not iOS-13.

UPDATE:

Apple's changelog/documentation for iOS-13 suggests:

The UITableViewCell class’s contentView property is always laid out edge-to-edge with adjacent accessories, both on the leading and the trailing side. This streamlines the layout code so developers who want the correct default offset no longer have to align their content with the content view border or the layout margin depending on whether there is an accessory on the trailing side or not. You should now always lay out their code on the layout margins of the cell’s content view to get the default system insets. These insets will be adjusted automatically based on the accessories visible in the cell to match the system’s default spacing. (48214114)

This is a bit unclear to me and if someone can help me out here.

Here are the snapshots as to how it is showing in iOS-12 which is required and how it is showing in iOS-13 respectively:

enter image description here

And here observe for iOS-13:

enter image description here

Here is also the Constraint Layout of my UITableViewCell's PriceView:

enter image description here

I need both to be consistent on both OSes. THANK YOU SO MUCH FOR THIS HELP!


Solution

  • Wohoo! I finally figured it out. So before as default it was working on iOS-12 but after iOS-13 and UITableViewCell changes as described in the question, it stopped working. Here is what I did:

    1. Firstly, in the Size Inspector, the ContentView of UITableViewCell was set to Safe Area Layout Guide which I turned off and turned on Safe Area Relative Margins, similarly I did the same for the child, as in the PriceView.
    2. Secondly, in the Attributes Inspector, the ContentView's and UITableViewCell's both had their Autoresize Subviews property turned on, I simply turned it off

    And voila! It works. Hope anyone who might have these UITableViewCell issues, please note that now its all relative 😉