1

I am having trouble performing an unwind segue to the previous view controller while preserving the previous view controllers preferred orientation. I have implemented categories in the tabbarcontroller, navcontroller, and various view controllers to override rotation methods, and aside from this one issue, these controllers maintain the supported views.

I have created a button on the modal view controller that unwinds to the previous controller. When I press this button while in landscape, it unwinds to the previous, but in landscape, although the viewcontroller's preferred/supported orientation is portrait.

I would like to perform this unwind segue while not allowing it to display the controller as landscape (segue's back to portrait). I have included a short video showing my problem.

https://www.dropbox.com/s/a5epj9tpmk85cnv/segueproblem.mov

TabBarController.m

@implementation UITabBarController (autoRotate)

- (BOOL)shouldAutorotate {
    return [self.selectedViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations {
    return [self.selectedViewController supportedInterfaceOrientations];
}

NavController.m

@implementation UINavigationController (autoRotate)


- (BOOL)shouldAutorotate {
    return [self.visibleViewController shouldAutorotate];
}

- (NSUInteger)supportedInterfaceOrientations {
    return [self.visibleViewController supportedInterfaceOrientations];
}

BViewController.m

@implementation BViewController

- (BOOL)shouldAutorotate {
    return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}
- (IBAction)unwindToViewControllerNameHere:(UIStoryboardSegue *)segue {
}

CViewController.m

@implementation CViewController

- (BOOL)shouldAutorotate {
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}


- (IBAction)backbutton:(id)sender {
}
jclark754
  • 914
  • 2
  • 12
  • 30
  • Try adding some logging or breakpointing to your `supportedInterfaceOrientations` and look to see what is happening at the moment of dismissal. Are they being consulted? Are they returning the answer you want them to return? – matt Jul 01 '14 at 01:25
  • By the way, in iOS 8 [this isn't going to work at all](http://stackoverflow.com/questions/24463543/how-do-we-dictate-app-orientation-in-ios-8), it seems, so you might want to start moving away from this entire model. – matt Jul 01 '14 at 01:27
  • Hi Matt, thanks for the response, what methods would you suggest implementing to prepare for iOS 8 instead? I am simply trying to force two view controllers in my entire project to all orientations and restrict the remainder to portrait inside tabcontroller>navcontrollers – jclark754 Jul 01 '14 at 01:29
  • Whoops, your link was super camouflage and I didn't catch it the first time around, seems in iOS 8 you won't be able to restrict individual view controllers to certain orientations per the comments on your link. Unfortunate as I am simply trying to display maps from our web server and allow the user preference on orientation. Previous view controllers (drilldown tableviews) really have no business in landscape. Back to the drawing board. Any pro tips? – jclark754 Jul 01 '14 at 01:33
  • In iOS 8, it seems, you are expected to be adaptable. There is no reason why table views can't be shown in landscape, after all. – matt Jul 01 '14 at 01:37
  • yup. Consider deleting and posting as an answer and I'll give you some rep. Also,I own one of your books but admittedly, I haven't read it yet. Don't judge me. – jclark754 Jul 01 '14 at 01:42

1 Answers1

-1

I don't think you need a lot of that code.

Try this:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortRait animated:YES];
Mika
  • 5,807
  • 6
  • 38
  • 83
  • not sure who gave you the downvote, but this method only truly orients the statusbar back to the top of the viewcontroller, it does not take the remainder of the vc with it. I placed this code in viewdidappear method – jclark754 Jul 01 '14 at 00:40