在旋转时推出新的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];
}
}
提前致谢! 杰里米
答案 0 :(得分:0)
知道了。而不是pushViewController推送在语句外设置的nvs。我在使用self.landscapeViewController时直接引用它。
以下是代码。希望这可以帮助将来的某个人。
self.landscapeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeView"];
[self.navigationController pushViewController:self.landscapeViewController animated:YES];