【问题标题】:Pushing a Storyboard to a new UIView将 Storyboard 推送到新的 UIView
【发布时间】:2013-09-16 22:53:18
【问题描述】:

在旋转时推送新的 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];
}    

}

提前致谢! 杰里米

【问题讨论】:

    标签: uiviewcontroller uistoryboard screen-rotation


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-04
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-14
      • 1970-01-01
      相关资源
      最近更新 更多