Note that there are some explanatory texts on larger screens.

plurals
  1. POViewWillAppear not getting called with UISplitViewController
    text
    copied!<p>Background &amp; Objective: I have a UISplitViewController based iPad app - till now it supported 4 orientations but now I want to lock it down to only landscape. I changed <code>shouldAutorotateToInterfaceOrientation</code> of the left view controller to support only landscape mode, but this stops its <code>viewWillAppear</code> from getting called.</p> <p>Details: My iPad's view controllers are organized as below:</p> <pre><code>window `-- splitVC (UISplitViewController) `-- rootNav (UINavigationController) `-- hvc (HostManagerViewController, derived from UIViewController) `-- detailViewController (DetailViewController, derived from UIViewController) </code></pre> <p>This is implemented in the App Delegate as below:</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { HostManagerViewController *hvc = [[[HostManagerViewController alloc] initWithNibName:nil bundle:nil] autorelease]; self.detailViewController = [[[DetailViewController alloc] initWithNibName:nil bundle:nil] autorelease]; UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:hvc] autorelease]; UISplitViewController *splitVC= [[[UISplitViewController alloc] init] autorelease]; [splitVC setViewControllers:[NSArray arrayWithObjects:rootNav, detailViewController, nil]]; splitVC.delegate = detailViewController; [window addSubview:splitVC.view]; [window setRootViewController:splitVC]; return YES; } </code></pre> <p><code>viewWillAppear</code> gets called when both <code>DetailViewController.m</code> and <code>HostManagerViewController.m</code> contain</p> <pre><code>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } Console output: Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 3 Hostmanager: Viewdidload Should rotate called to hostmanager with 1 Hostmanager: viewwillappear </code></pre> <p>But when I change <code>HostManagerViewController</code>'s code to</p> <pre><code>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (UIInterfaceOrientationIsLandscape(interfaceOrientation)); } </code></pre> <p>then 'viewWillAppear` of HostManagerViewController is not invoked. Console output</p> <pre><code>Should rotate called to hostmanager with 1 (1 is the numeric value of interfaceOrientation) Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 3 Should rotate called to hostmanager with 3 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 3 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 3 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 1 Should rotate called to hostmanager with 3 Hostmanager: Viewdidload Should rotate called to hostmanager with 1 </code></pre> <p>Only Landscape modes are supported in the Info.plist</p> <p>EDIT: Inserted NSLog messages to track <code>shouldAutorotateToInterfaceOrientation</code>, <code>viewWillAppear</code> and <code>ViewDidLoad</code></p>
 

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