ios - 应用程序试图在目标上呈现一个 nil 模态视图 Controller

标签 ios xcode

我有一个简单的单 View 应用程序,其中包含两个 Storyboard,纵向和横向布局不同。景观布局完全不同,这就是我使用第二个 Storyboard的原因。

当我切换到横向时, View 没有改变,我得到了

"Application tried to present a nil modal view controller on target"

` 调试器错误。我已经检查过景观 Storyboard 是否引用了 CalculatorViewController 类。

这是产生错误的代码行:

[self presentViewController:landscapeViewController animated:YES completion:nil];

这是来自 CalculatorViewController.m 的整个方法:

- (void)orientationChanged:(NSNotification *)notification

{    
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
        if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
           !isShowingLandscapeView)        
    {
       // code here to show landscape storyboard
        UIStoryboard *landscapeStoryboard = [UIStoryboard storyboardWithName:@"LandscapeStoryboard" bundle:nil];

        CalculatorViewControllerLandscape *landscapeViewController = [landscapeStoryboard instantiateInitialViewController];
        [self presentViewController:landscapeViewController animated:YES completion:nil];
        isShowingLandscapeView = YES;
    }    
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) &&             
         isShowingLandscapeView)        
    {        
        [self dismissViewControllerAnimated:YES completion:nil];        
        isShowingLandscapeView = NO;        
    }
}

初始 View Controller 称为 CalculatorViewController。 横向布局的 View Controller 称为 CalculatorViewControllerLandscape。

这是我的第一个应用程序,非常感谢任何帮助。我试图在未成功发布的类似问题中找到解决方案。

最佳答案

这意味着landscapeViewControllernil

这可能是由于:

  • landscapeStoryboardnil(很可能是因为找不到名为 LandscapeStoryboard 的 Storyboard)
  • Storyboard中没有指示初始 View Controller 。

关于ios - 应用程序试图在目标上呈现一个 nil 模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18461931/

相关文章:

Xcode 在处理 swift 文件时崩溃

ios - 如何在 iBook 中像打开书一样制作动画?

ios - 频繁点击按钮

ios - xcode - 表格 View 下的进度条

ios - 如果从应用商店或 testflight 下载 iPhone 应用程序崩溃

ios - 如何将详细 View Pane 标题设置为当前所选单元格的名称?

iOS 复杂动画协调,如 Android Animator(Set)

ios - 当SwiftUI中观察到的对象发生变化时如何禁用列表中的动画?

ios - did设置使用建议?

ios - 如何修复已吊销的证书?