【问题标题】:Error on application tried to present a Split View Controllers modally应用程序错误尝试以模态方式呈现拆分视图控制器
【发布时间】:2012-08-07 10:30:07
【问题描述】:

我正在使用故事板,我想加载一组特定的 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;
}

【问题讨论】:

    标签: iphone ios xcode ipad


    【解决方案1】:

    问题看起来很明显。以下内容抄自UISplitViewController 文档:

    "您必须始终从 UISplitViewController 对象安装视图 作为应用程序窗口的根视图。 [...] 拆分视图 控制器不能以模态方式呈现。”

    换句话说,你看到的是预期的行为。

    【讨论】:

    • 你能确认它们应该如何呈现吗?
    • @drlobo -- 假设应用程序委托中的代码,类似于:self.window.rootViewController = self.splitViewController;
    猜你喜欢
    • 2013-12-18
    • 1970-01-01
    • 2022-01-11
    • 2011-12-16
    • 2018-08-24
    • 2023-01-25
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多