Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>When you use <code>addChildViewController</code> to add the <code>ContentPortraitVC</code>:</p> <p>a. The <code>ContentPortraitVC</code> gets its <code>parentViewController</code> property set. </p> <p>b. You then (as per the Apple documentation) have to manually display the <code>ContentPortraitVC</code>'s view. If you follow the documentation you do this by adding it as a <strong>child</strong> of the <code>ControllerVC</code>'s top level view.</p></li> <li><p>The <code>ContentPortraitVC</code> then calls <code>presentViewController</code> to display <code>ContentModalDetailVC</code>. </p> <p>a. This sets its <code>presentingViewController</code> property (in the debugger this is shown as the <code>_parentModalViewController</code> ivar -- note the ivar is different from the property), and sets the <code>presentedModalViewController</code> property of the <code>ContentPortraitVC</code> (who's ivar is <code>_childModalViewcontroller</code>). </p> <p>b. Views wise, on iPhone, the <code>ContentModalDetailVC</code>'s view will completely replace the views from <code>ContentPortraitVC</code> and <code>ContainerVC</code>, so only the modal view controller's view will be visible. (on iPad, it layers the new UI over the top, but as a <strong>sibling</strong> of the <code>ControllerVC</code>'s view, which in turn is the parent of <code>ContentPortraitVC</code>'s view).</p></li> <li><p>So now, you transition from <code>ContentPortraitVC</code> to <code>ContentLandscapeVC</code>.</p> <p>a. IOS does a bit of magic. It knows that the thing you are removing (<code>ContentPortraitVC</code>) has a <code>presentedViewController</code> currently active, so it changes its parent. It sets the value to <code>nil</code> on <code>ContentPortraitVC</code>, takes the child (the <code>ContentModalDetailVC</code>) and sets its parent to the new view (<code>ContentLandscapeVC</code>). So now the view controller that presented the modal view <em>is no longer its presenting view controller</em>. It is as if <code>ContentLandscapeVC</code> presented it in the first place!</p> <p>b. In terms of views, you follow the Apple docs to change over the view from <code>ContentPortraitVC</code> to <code>ContentLandscapeVC</code>. But you are simply changing the subviews of <code>ControllerVC</code>'s view. On iPhone, the modal view controller is still the only thing being displayed, so making the change doesn't do anything on screen. On iPad, it does (though you probably won't see it, as the modal view is usually full screen).</p></li> <li><p>Now you come to dismiss the modal view. Presumably you do this in <code>ContentPortraitVC</code>, but it no longer has any reference to the thing it presented. So calling <code>[self dismissViewController...</code> does nothing, because <code>ContentPortraitVC</code> is no longer presenting anything, responsibility for that has been passed on to <code>ContentLandscapeVC</code>.</p></li> </ol> <p>So that's what happens and why. Here's what to do about it.</p> <ol> <li><p>You can rewire the delegate manually when you change from <code>ContentPortraitVC</code> to <code>ContentLandscapeVC</code>, so the latter is the one that tries to dismiss the modal controller.</p></li> <li><p>You can have the modal controller dismiss itself with <code>[self dismissModalControllerAnimated:YES completion:nil]</code>. I'm going to ask and answer another question on why that works (how does IOS know which to dismiss?), if that seems strange.</p></li> <li><p>You can have the <code>ControllerVC</code> be the one that pops up the modal view and be responsible for removing it.</p></li> </ol>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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