I have a simple single view app with two storyboards with different layouts for portrait and landscape. The landscape layout is completely different which is why I am using a second storyboard.
When I switch to landscape the view doesn't change and I get the
"Application tried to present a nil modal view controller on target"
` error in the debugger. I have checked that the landscape storyboard is referencing to the CalculatorViewController class.
This is the line of code which generates the error:
[self presentViewController:landscapeViewController animated:YES completion:nil];
Here is the whole method from 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;
}
}
The Initial View Controller is called CalculatorViewController. The View Controller for the landscape layout is called CalculatorViewControllerLandscape.
This is my first app so I really appreciate any help. I have tried to find a solution in similar questions posted without success.