UISplitViewController is not rotating correctly

风流意气都作罢 提交于 2019-12-12 02:48:21

问题


I know there is a lot of discussion on this topic on stack overflow, but none of the questions have an answer that works for me.

I have a SplitViewController that loads as the root view controller, and both of the tableviews inside the SVC have ShouldAutoRotate set to return YES.

The SVC won't rotate with the iPad correctly, even though the clock / status bar do.


Update

In my AppDelegate, I've noticed that the rootViewController isn't actually set until after I set it - shouldn't the rootViewController always be set? This code:

    MyAppAppDelegate *appDelegate = (MyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSLog(@"RootViewController pre set: %@", appDelegate.window.rootViewController);
    [appDelegate.window setRootViewController:splitViewController];
    NSLog(@"RootViewController post set: %@", appDelegate.window.rootViewController);

Logs as:

RootViewController pre set: (null)
RootViewController post set: <UISplitViewController: 0x88ad2d0>

Does this mean that I am mistaken in thinking the SVC is the root view controller?

Also, in IB - the window has nothing hooked up to the rootViewController outlet - is this a problem?


Here's where the SVC is programmatically made:

-(IBAction)makeStory:(id)sender{
 MakeSentenceTableViewController *detailViewController = [[MakeSentenceTableViewController alloc] initWithNibName:@"MakeSentenceTableViewController" bundle:nil];

    UISplitViewController *splitViewController = [[[UISplitViewController alloc] init] autorelease];

    UINavigationController *rootNav = [[[UINavigationController alloc] initWithRootViewController:makeStoryTableViewController]autorelease];

    UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];

    splitViewController.viewControllers = [NSArray arrayWithObjects:rootNav, detailNav, nil];
    splitViewController.delegate        = makeStoryTableViewController;

    MyAppAppDelegate *appDelegate = (MyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate.window setRootViewController:splitViewController];
}

Here is the ShouldAutoRotate section in both tableviews (they're identical in both):

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {  
    NSLog(@"story idiom for rotate is iPad");
    return YES;
}

Please help me fix this so that the SplitViewController loads correctly - or help me out with some techniques to debug (e.g. how could I check for sure that the SVC is in the rootViewController, are there other methods to debugging rotation hassles?).


回答1:


Ah. So often part of the process in asking a question leads you to answer it to yourself.

I had to hook up the rootViewController outlet in IB for MainWindow~ipad.xib to the viewController in the AppDelegate, then everything started working.

So I hadn't correctly set the UISplitViewController as the rootViewController.



来源:https://stackoverflow.com/questions/9612036/uisplitviewcontroller-is-not-rotating-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!