0

在旋转时推送新的 UIView 仍然存在问题。我正在关注我发现的一个例子。离得太近了 它在这一点上出现错误,错误为;

'NSInvalidArgumentException',原因:'应用程序试图在目标上呈现一个 nil 模态视图控制器。'

controller nvs = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeView"];
[self.navigationController pushViewController:nvs animated:YES]

显然,我在这里遗漏了一些东西。我想要实现的是当用户旋转他们的设备时推送到堆栈上的不同视图。像日历一样。

整个声明

LandscapeViewController * nvs;

- (void)updateLandscapeView { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;

if (UIDeviceOrientationIsLandscape(deviceOrientation) && self.presentedViewController == nil)

{
    if (!self.landscapeViewController)
        //self.landscapeViewController = [[LandscapeViewController alloc] initWithNibName:@"LandscapeView" bundle:nil];

        //Set the location of the where you want the view to go i.e. the next view controller
        nvs = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeView"];
        //Push the view onto the device
        [self.navigationController pushViewController:nvs animated:YES];

    if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
        [self presentViewController:self.landscapeViewController animated:YES completion:NULL];
    else
        [self presentModalViewController:self.landscapeViewController animated:YES];
}
else if (deviceOrientation == UIDeviceOrientationPortrait && self.presentedViewController != nil)
{
    if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
        [self dismissViewControllerAnimated:YES completion:NULL];
    else
        [self dismissModalViewControllerAnimated:YES];
}    

}

提前致谢!杰里米

4

1 回答 1

0

知道了。而不是 pushViewController 推送在语句之外设置的 nvs。我在使用 self.landscapeViewController 时直接引用了它。

下面是代码。希望这对将来的某人有所帮助。

self.landscapeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeView"];
 [self.navigationController pushViewController:self.landscapeViewController animated:YES];
于 2013-09-17T02:11:05.850 回答