2012-03-08 61 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。