iphone - 应用程序尝试以模态方式呈现 Split View Controller 时出错

标签 iphone ios xcode ipad

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

最佳答案

问题看起来很明显。以下是从 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."

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

关于iphone - 应用程序尝试以模态方式呈现 Split View Controller 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11843991/

相关文章:

ios - 在 iOS 上获取电池健康信息

iphone - *AppDelegate.m 中的导航栏样式更改

ios - 在 iOS 15 之前,我只能发送声音本地通知,现在我必须显示横幅

ios - 从应用商店安装后是否可以获取链接内容?

ios - 从命令行运行 'Cedar' 单元测试时出错

ios - 如何检测音量加减被按下

iphone - Google新闻RSS供稿返回didFailWithError -1002代码

iphone - 智能手机可以从几英尺的距离(不是 NFC)读取 RFID 标签吗?

iphone - iphone 应用程序更新的新私钥和配置文件

xcode - 为什么 block 参数没有自动完成?