Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS - Change View with the device orientation
    text
    copied!<p>I'm using iOS5 and storyboard. I have two view with two different identifier. I want change the view when change the orientation of the device. This is my code:</p> <pre><code>- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight))){ self.view = [self.storyboard instantiateViewControllerWithIdentifier:@"Landscape"]; } else if(((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))){ self.view = [self.storyboard instantiateViewControllerWithIdentifier:@"Portrait"]; } return YES; } </code></pre> <p>But the app crash. Which is the problem?</p> <p>EDIT: If I add two uiview and I put the two id to the uiview when I rotate the device It crash. This is the code:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil]; } - (void) orientationChanged:(id)object { portraitView = [self.storyboard instantiateViewControllerWithIdentifier:@"TermoregolatoreTop"]; landscapeView = [self.storyboard instantiateViewControllerWithIdentifier:@"Landscape"]; UIInterfaceOrientation interfaceOrientation = [[object object] orientation]; if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { self.view = self.portraitView; } else { self.view = self.landscapeView; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload