我尝试按照Apple recommendations更改ViewController,将设备方向从“纵向”更改为“横向”。执行代码时,我总是收到错误消息:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target
。
我无法弄清问题是什么。这是执行终止的部分(PortraitViewController的一部分):
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && self.presentedViewController == nil){
if (!self.resultViewLandscapeViewController){
[self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeViewController"];
NSLog(@"LandscapeView initiated"); //this is called when device is turned
}
[self presentViewController:self.resultViewLandscapeViewController animated:YES completion:NULL];
//after the code above the execution is interrupted and the error message is thrown
}
else if (deviceOrientation == UIDeviceOrientationPortrait && self.presentedViewController != nil){
[self dismissViewControllerAnimated:YES completion:NULL];
}
}
答案 0 :(得分:1)
创建后,您实际上并未设置viewcontroller。
self.resultViewLandscapeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeViewController"];
感谢@Arbitur指出