Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a Related issue that I am compelled to address, which hopefully will save someone else a day of debugging:</p> <p>I am finding out that in Storyboard:</p> <ol> <li><strong><code>segue-push</code></strong> does <strong>not</strong> cause <code>subView</code>s to be laid out at <code>-viewDidLayoutSubviews</code> (<em>they are instead laid out at some other time just before <code>-viewDidAppear</code></em>).<br> <strong>Whereas</strong>... </li> <li><strong><code>segue-modal</code></strong> and <code>[navController.storyboard presentViewController:]</code> <strong>does</strong> cause <code>subViews</code> to be laid out at <code>-viewDidLayoutSubviews</code>. </li> </ol> <p>The solution is to put <code>[self.mySubView layoutSubviews]</code> within the <code>viewController</code>'s <code>-viewDidLayoutSubviews</code> method in order to manually load the <code>subView</code>s within <code>mySubView</code>.</p> <p>My case was that I had a custom gradient button that was not properly initializing it's visual appearance.<br> The button was contained within a <code>scrollView</code> that contained a <code>CustomView</code> which contained the custom gradient button.<br> So, basically... a button within a view within a <code>scrollView</code>. </p> <p>The app starts out with a <code>UINavigationController</code> having some other <code>ViewController1</code> loaded.<br> <code>ViewController1</code> contains a button which, when pressed, launches a storyboard <strong><code>segue-push</code></strong> to <code>ViewController2</code>.<br> (<em>this was arranged in storyboard by control-dragging from the button in <code>ViewController1</code> to <code>ViewController2</code></em>).</p> <p><code>ViewController2</code> contains the <code>scrollview</code>/<code>customView</code>/<code>customButton</code>.<br> In <code>ViewController2</code>'s <code>-viewDidLayoutSubviews</code>, I initialize the <code>customButton</code> which is a custom Gradient Button having it's own <strong>.h/.m</strong> files.<br> <code>GradientButton.m</code> has an <code>initLayers</code> method which configures it graphically and requires the <code>bounds</code>/<code>frame</code> property of the button to be initialized.<br> <strong>However</strong>...<br> in <code>ViewController2</code>'s <code>-viewDidLayoutSubviews</code>, <code>self.customButton</code> had a frame of 0,0,0,0.</p> <h2>A few notes:</h2> <ol> <li>Yes, I am calling <code>[super viewDidLayoutSubviews]</code> at the beginning of <code>-viewDidLayoutSubviews</code>. </li> <li>The only view that has been laid out at <code>-viewDidLayoutSubviews</code> is <code>self.view</code> (<code>ViewController2</code>'s initial view, as connected in Storyboard's connections panel. <em>in my case - <code>self.view</code> is a <code>scrollView</code></em>).</li> </ol> <h2>To resolve:</h2> <ol> <li>in <code>ViewController2</code>, I created an outlet <code>self.bottomView</code> for the view that contained <code>self.customButton</code>. </li> <li>in <code>ViewController2</code>'s <code>-viewDidLayoutSubviews</code>, I call <code>[self.bottomView layoutSubviews]</code> <ul> <li>This will then cause <code>customButton</code>'s frame/bounds to be properly set. </li> </ul></li> <li>Next, I call <code>[self.customButton initLayers]</code> which now properly initializes my custom gradient button. </li> </ol> <p>A few notes about <code>ViewController2</code>'s <code>-viewDidLayoutSubviews:</code> calling <code>[self.view layoutSubviews]</code> causes <code>bottomView</code>'s frame to be initialized, but NOT <code>customButton</code>'s frame.<br> In terms of a view hierarchy, <code>-layoutSubviews</code> applies only to the <code>subView</code>s of <code>self.view</code> and not to any <code>subView</code>s of those <code>subView</code>s.<br> This only appears to be the case with storyboard <strong><code>segue-push</code></strong>. </p> <p>The storyboard <strong><code>segue-modal</code></strong> and the programmatic <code>[navController presentViewController]</code> both seem to correctly initialize all levels of the view hierarchy (all "<code>subView</code>s of <code>subView</code>s") by the time <code>-viewDidLayoutSubviews</code> is called.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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