0

我尝试按照 Apple 的建议将 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];
}
}
4

1 回答 1

1

You aren't actually setting the viewcontroller after creating it.

self.resultViewLandscapeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeViewController"];

Thanks to @Arbitur for pointing that out

于 2013-08-14T21:39:22.687 回答