Note that there are some explanatory texts on larger screens.

plurals
  1. POCentering subview's X in autolayout throws "not prepared for the constraint"
    primarykey
    data
    text
    <p>I have a custom UIView subclass which is being initialized via a nib.</p> <p>In <code>-awakeFromNib</code>, I'm creating a subview and attempting to center it in its superview.</p> <pre><code>[self setInteralView: [[UIView alloc] init]]; [[self internalView] addConstraint: [NSLayoutConstraint constraintWithItem: [self internalView] attribute: NSLayoutAttributeCenterX relatedBy: NSLayoutRelationEqual toItem: self attribute: NSLayoutAttributeCenterX multiplier: 1 constant: 0]]; </code></pre> <p>This breaks, and causes the following output:</p> <pre><code>2013-08-11 17:58:29.628 MyApp[32414:a0b] The view hierarchy is not prepared for the constraint: &lt;NSLayoutConstraint:0xc1dcc80 UIView:0xc132a40.centerX == MyView:0xc1315a0.centerX&gt; When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug. 2013-08-11 17:58:29.630 MyApp[32414:a0b] View hierarchy unprepared for constraint. Constraint: &lt;NSLayoutConstraint:0xc1dcc80 UIView:0xc132a40.centerX == MyView:0xc1315a0.centerX&gt; Container hierarchy: &lt;UIView: 0xc132a40; frame = (0 0; 0 0); clipsToBounds = YES; layer = &lt;CALayer: 0xc132bc0&gt;&gt; View not found in container hierarchy: &lt;MyView: 0xc1315a0; frame = (-128 -118; 576 804); layer = &lt;CALayer: 0xc131710&gt;&gt; That view's superview: &lt;UIView: 0xc131a70; frame = (0 0; 320 568); autoresize = W+H; layer = &lt;CALayer: 0xc131b50&gt;&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload