2012-03-08 59 views
0

我知道关于堆栈溢出这个话题有很多讨论,但没有一个问题有答案适用于我。UISplitViewController没有正确旋转

我有一个SplitViewController作为根视图控制器加载,并且SVC内部的两个tableviews都将ShouldAutoRotate设置为返回YES。

即使时钟/状态栏有效,SVC也不会正确旋转iPad。


更新

在我的AppDelegate,我已经注意到,RootViewController的是不实际设置直到后,我把它 - 不应在RootViewController的始终设置? 此代码:

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

日志为:

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

这是否意味着我在思考的SVC是根视图控制器弄错了?

此外,在IB - 窗口没有任何连接到rootViewController插座 - 这是一个问题?


下面是其中SVC是编程制作:

-(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]; 
} 

这里是两个tableviews的ShouldAutoRotate部分(他们两个是相同的):

// 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; 
} 

请帮助我解决这个问题,以便SplitViewController正确加载 - 或者用一些技术来帮助我调试(例如,我怎样才能确定SV C在rootViewController中,是否有其他方法来调试旋转的麻烦?)。

回答

1

啊。因此,在提问时,通常会有一部分过程会引导您自己回答。

我不得不在IB中为MainWindow〜ipad.xib连接到AppDelegate中的viewController的rootViewController插座,然后一切开始工作。

所以我没有正确设置UISplitViewController作为rootViewController。