应用程序出现错误,尝试以模态方式显示Split View Controllers [英] Error on application tried to present a Split View Controllers modally

查看:73
本文介绍了应用程序出现错误,尝试以模态方式显示Split View Controllers的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用情节提要,并且要加载一组特定的XIB,问题是我遇到了此错误:

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>

PlaceHolderViewController中,我有一个使用该代码加载xib的按钮,我从iPhone加载xib没问题,但是在iPad上却遇到了这个问题.

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.

这是代码:

- (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文档复制的:

The problem looks obvious. The following is copied from the UISplitViewController documentation:

"您必须始终从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."

换句话说,您所看到的是预期的行为.

In other words, what you're seeing is intended behavior.

这篇关于应用程序出现错误,尝试以模态方式显示Split View Controllers的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆