2012-08-07 69 views
0

我用故事板,我想加載一組特定的XIBs的,問題是,我得到這個錯誤:錯誤應用試圖呈現拆分視圖控制器模態

'NSInvalidArgumentException', reason: 'Application tried to present a Split View Controllers modally <PlaceHolderViewController: 0x38e890> 

PlaceHolderViewController我有一個按鈕,用這段代碼加載xib,我沒有問題從iPhone加載xib,但在iPad上我遇到了這個問題。

這是代碼:

- (IBAction)actionButtonConversor:(id)sender { 
    ConverterViewController *converterViewController; 
    UnitSelectViewController *unitSelectViewController; 

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     converterViewController = [[ConverterViewController alloc] initWithNibName:@"ConverterViewController_iPhone" bundle:nil]; 
     unitSelectViewController= [[UnitSelectViewController alloc] initWithNibName:@"UnitSelectViewController_iPhone" bundle:nil]; 
     self.navigationController = [[UINavigationController alloc] initWithRootViewController:converterViewController]; 
     self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0f green:0.48235297203063965f blue:0.63137257099151611f alpha:1]; 
     [self presentModalViewController:self.navigationController animated:YES]; 
    } else { 
     converterViewController = [[ConverterViewController alloc] initWithNibName:@"ConverterViewController_iPad" bundle:nil]; 
     unitSelectViewController= [[UnitSelectViewController alloc] initWithNibName:@"UnitSelectViewController_iPad" bundle:nil]; 
     UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:unitSelectViewController]; 
     UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:converterViewController]; 
     masterNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0f green:0.48235297203063965f blue:0.63137257099151611f alpha:1]; 
     detailNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.0f green:0.48235297203063965f blue:0.63137257099151611f alpha:1]; 

     self.splitViewController = [[UISplitViewController alloc] init]; 

     self.splitViewController.delegate = converterViewController; 

     self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil]; 
     [self presentModalViewController:self.splitViewController animated:YES]; // ERROR comes from here i think 
    } 

    unitSelectViewController.delegate = converterViewController; 
    converterViewController.unitSelectViewController = unitSelectViewController; 
} 

回答

4

問題看起來明顯。以下是從UISplitViewController文件複製:

"you must always install the view from a UISplitViewController object as the root view of your application’s window. [...] Split view controllers cannot be presented modally."

換句話說,你看到的是預期的行爲。

+0

你能確認他們應該如何呈現? – drlobo 2013-12-02 10:54:08

+0

@drlobo - 假設應用程序委託內的代碼,如:'self.window.rootViewController = self.splitViewController;' – 2013-12-02 15:27:38

相關問題