iOS 13 UITableViewCell drops layout constraint changes

I've got a table view whose cells are configured with autolayout constraints to handle a couple of slightly different layouts depending on their contents. I make the changes by setting the active property on the constraints that I want to activate or deactivate. This works fine until I put the app into the background and return to it. When I do this, it looks like my changes are lost and the cells' layout constraints return to the state they originally had in their nib file.


This only occurs when running on iOS 13 with a build from Xcode 11. If I run on iOS 12 with a build from Xcode 10.3 or Xcode 11 I do not see this issue. If I run on iOS 13 with a build from Xcode 10.3 I do not see this issue.


I've tried putting a symbolic breakpoint at -[NSLayoutConstraint setActive:] but it does not get hit when putting the app into the background or returning it to the foreground.


Has anybody else run into an issue like this? Any hints? Thanks!

In such case, I first change the Presentation of ViewController from Automatic to FullScreen in IB (because that may change which delegate functions are called).


Could you give it a try ?

That appears to have no effect.

I've created a small project demonstrating this issue.
https://github.com/cooksey/CellLayout
Run the program, and it shows a table view cell with a label next to an image. Leave the app for the home screen, then return to the app, and it now shows the label overlapping the image.

So we should look at some code.


it looks like my changes are lost and the cells' layout constraints return to the state they originally had in their nib file.


Could you show where you make the changes ?

And how you declared the constraints in code.

Yes, I've got a sample project up on GitHub, but the reply with the link is awaiting moderation. (github)/cooksey/CellLayout

Please, post also the most relevant parts here, to avoid having to go and load the project on github.


Have you asked for a reloadData() in applicationDidBecomeActive

I use Xcode 12.0.1 (12A7300), testing on iOS14 devices and I have the exact same issue. I have noticed that the constraints are being reset at the time the app goes in the background.

For now, to temporarily fix the issue, I check if the contraints are valid in the layoutSubviews() function in my UITableViewCell. If not, I set them to what they are supposed to be.

If you have solved the issue in any other way I would highly appreciate your update :)
iOS 13 UITableViewCell drops layout constraint changes
 
 
Q