Question

Still having issues with pushing a new UIView on rotation. I am following an example that I found. It's SO freaking close. It wigs out with an error at this point with the error of;

'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target .'

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

Clearly, I'm missing something here. What I'm trying to achieve is a different view pushed onto the stack when the user rotates their device. Like calendar.

Entire statement

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];
}    

}

Thanks in advance! Jeremy

Was it helpful?

Solution

Got it. Rather then pushViewController pushing nvs which was set outside the statement. I referenced it directly in using self.landscapeViewController.

Below is the code. Hope this helps someone in the future.

self.landscapeViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeView"];
 [self.navigationController pushViewController:self.landscapeViewController animated:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top