我有一个简单的单 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。
这是我的第一个应用程序,非常感谢任何帮助。我试图在未成功发布的类似问题中找到解决方案。
最佳答案
这意味着landscapeViewController
是nil
。
这可能是由于:
landscapeStoryboard
为nil
(很可能是因为找不到名为LandscapeStoryboard
的 Storyboard)- Storyboard中没有指示初始 View Controller 。
关于ios - 应用程序试图在目标上呈现一个 nil 模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18461931/