AMBIGUOUS LAYUOT printed for views not in the hierarchy (child view controllers)

Number:rdar://36318204 Date Originated:January 5 2018
Status:Open Resolved:
Product:iOS SDK Product Version:11.2
Classification:Other bug Reproducible:Always

This bug consists of two parts that play together. 

1. When entering "Debug View Hierarchy" mode, all child view controllers' views are triggered, even on controllers that have not loaded their views yet. This causes the views to be created, but not laid out. 

2. When entering "Debug View Hierarchy" mode, if a child view controller of a visible view controller has it's view loaded but not added to the view hierarchy (often caused by #1), ambiguous layout is reported and printed to the console. 

In complex apps with UITabBarController, UINavigationControllers and custom containers this could result in many warnings printed when entering "Debug View Hierarchy" mode, making it hard to see real issues. 

#1 is a minor issue or maybe not an issue at all, but in combination with #2 makes view debugging hard.

This bug can be reproduced both with standard container view controllers (UITabBarController) and with custom ones. 
Attached samples: 
AmbiguousLayoutBug.xcodeproj - custom container
AmbiguousLayoutBugOnTabBarController.xcodeproj - sample tabbed application automatically created by Xcode (via New project menu), no modification added except "print viewDidLoad". 

Steps to Reproduce:

Setup: one view controller, that adds another view controller as a child, without adding it's view. 
1. Launch the application
2. Enter "Debug View Hierarchy" mode
3. Observe "viewDidLoad" is called on the children that haven't loaded their views before
4. Resume the app
5. Enter "Debug View Hierarchy" mode again
6. In the console "AMBIGUOUS LAYOUT" trace is printed for subviews of the child view controller's view. 

Expected Results:

1. "viewDidLoad" is not triggered on child view controllers that haven't had their views loaded previously upon entering "Debug View Hierarchy" mode
and / or
2. Upon entering "Debug View Hierarchy" mode, ambiguous layout should not be reported for views not in the view hierarchy.

Actual Results:
"viewDidLoad" is triggered on child view controllers that haven't loaded their views previously
Ambiguous layout trace is printed in the console for views not in the view hierarchy, that belong to a  child view controller.

iOS Simulator iPhone 7, iOS 11.2 (15C107)

Xcode 9.2 (9C40b)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!