我有一个简单的单视图应用程序,其中包含两个故事板,纵向和横向布局不同。景观布局完全不同,这就是我使用第二个故事板的原因。
当我切换到横向时,视图没有改变,我得到了
“应用程序试图在目标上呈现一个零模式视图控制器”
` 调试器中的错误。我检查了风景故事板是否引用了 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;        
    }
}
初始视图控制器称为 CalculatorViewController。横向布局的视图控制器称为 CalculatorViewControllerLandscape。
这是我的第一个应用程序,所以我非常感谢任何帮助。我试图在未成功发布的类似问题中找到解决方案。