错误应用试图呈现拆分视图控制器模态
问题描述:
我用故事板,我想加载一组特定的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;
}
答
问题看起来明显。以下是从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."
换句话说,你看到的是预期的行为。
你能确认他们应该如何呈现? – drlobo 2013-12-02 10:54:08
@drlobo - 假设应用程序委托内的代码,如:'self.window.rootViewController = self.splitViewController;' – 2013-12-02 15:27:38