Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: AutoRotating between NIBs
    primarykey
    data
    text
    <p>My universal app is a single full screen view. Pressing a button flips to reveal a settings page:</p> <pre><code>- (void) showSettings { FlipsideViewController * flipsideVC = [FlipsideViewController alloc]; NSString * settingsNib; if ( isIPad() ) settingsNib = isCurrentlyPortrait() ? @"settings_iPad_portrait" : @"settings_iPad_landscape"; else settingsNib = @"settings_iPhone"; [flipsideVC initWithNibName: settingsNib bundle: nil ]; flipsideVC.delegatePointingToMainVC = self; flipsideVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self presentModalViewController: flipsideVC animated: YES ]; [flipsideVC release]; } </code></pre> <p>and the settings page invokes the delegate method: I recreate the main view in light of the changed settings, and flip back.</p> <pre><code>- (void) settingsDidQuit:(FlipsideViewController *) flipsideVC { [self createOrRecreateWheelView]; [self dismissModalViewControllerAnimated: YES]; } </code></pre> <p>But what if the user rotates the iPad on the settings page? Apple decrees that my app must handle this. But how to do this? can I dynamically load a new XIB for the settings page? </p> <p>I can't see a way to do that, so my attempted solution is to catch the rotation within the settings view, ...</p> <pre><code>- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) oldInterfaceOrientation { [self.delegatePointingToMainVC settingsOrientationChanged]; } </code></pre> <p>...and call back to the main view controller, which dissolves the settings view controller and recreates it in light of the current orientation.</p> <pre><code>- (void) settingsOrientationChanged { [self dismissModalViewControllerAnimated: YES]; [self showSettings]; } </code></pre> <p>There is a trivial problem straight away -- didRotateFromInterfaceOrientation gets triggered automatically when the settings page loads. I can prevent this by setting a boolean to false in init, and modifying thus:</p> <pre><code>- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) oldInterfaceOrientation { if (initialized) [self.delegatePointingToMainVC settingsOrientationChanged]; initialized = true; } </code></pre> <p>problem with this approach is that I navigate to the settings page, rotate the device, and it momentarily shows the correct settings page, before flicking back to my main view.</p> <p>I think there is a threading problem here. But maybe my whole approach is wrong. Can somebody suggest a better solution?</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.
 

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