我正在使用故事板,我想加载一组特定的XIB,问题是我收到了这个错误:
'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; }I'm using storyboards and I want to load a specific set of XIBs, the problem is that I'm getting this error:
'NSInvalidArgumentException', reason: 'Application tried to present a Split View Controllers modally <PlaceHolderViewController: 0x38e890>In the PlaceHolderViewController I have a button that loads the xib with this code, I have no problem loading the xib from the iPhone but on the iPad I'm having this problem.
This is the code:
- (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文档复制以下内容:
“你必须始终从UISplitViewController对象安装视图作为应用程序窗口的根视图。[...]拆分视图控制器不能以模态方式显示。”
换句话说,你所看到的是预期的行为。
The problem looks obvious. The following is copied from the UISplitViewController documentation:
"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."
In other words, what you're seeing is intended behavior.
更多推荐
发布评论