Search code examples
iphoneiosuiinterfaceorientationuistoryboardsegue

iOS - Change view when orientation changes


I use iOS5 with storyboards, I created two ViewController, one for the portrait orientation and one for the landscape.. I connected the two views with two "modal segue" and this is the code that I used:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation))
{
    [self performSegueWithIdentifier: @"aaaa" sender: self];
}
else if (deviceOrientation == UIDeviceOrientationPortrait)
{
    [self performSegueWithIdentifier: @"ddd" sender: self];
}    

return true;

}

If I change from portrait to landscape it works but when I return to portrait view it crashes with "has no segue with identifier 'ddd'" but it exists.

Thanks.


Solution

  • I have resolved setting a modal segue between the views and then into the implementation file with this code:

    - (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
    {
       if(self.interfaceOrientation == UIDeviceOrientationPortrait || self.interfaceOrientation == UIDeviceOrientationPortraitUpsideDown){
    
           [self performSegueWithIdentifier: @"aaaa" sender: self];
    
       } else  if(self.interfaceOrientation == UIDeviceOrientationLandscapeLeft || self.interfaceOrientation == UIDeviceOrientationLandscapeRight)
       {
    
           [self performSegueWithIdentifier: @"ddd" sender: self];
       }
    }
    

    Course for both the ViewController (portrait and landscape).