Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8656753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:21:27+00:00 2026-06-12T15:21:27+00:00

I have a class of UINavigationController (and linked to the storyboard mainNavCont) containing: –

  • 0

I have a class of UINavigationController (and linked to the storyboard “mainNavCont”) containing:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"init"); 
}

- (void)viewDidAppear:(BOOL)animated
{
    NSLog(@"View Appeared");
    UINavigationController *selfNavController = [self navigationController];
    [selfNavController performSegueWithIdentifier:@"rootToPortSeg" sender:self];
}

There is a segue in the storyboard with the identifier “rootToPortSeg”, type is “push”, that links to a UIViewController called “portViewCont”. In that class there is the following:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"I am the port");
}

Everything compiles fine and I get no errors in Xcode. But the portViewCont UIViewController never loads or displays or anything. I am still new to iOS and for the life of me I can’t figure out what I am doing wrong. I get “init” and “View Appeared” in the console but not “I am the port”, Thanks SO!

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:21:28+00:00Added an answer on June 12, 2026 at 3:21 pm

    After thinking some more about this problem, I think the best way to go would be to use a custom container controller with a portraitController and landscapeController as its children.

    In the following code, I instantiate the 2 child controllers in the container controller’s init method, and have strong properties pointing to them so, that when switching back and forth, you’ll be accessing the same instances. I set up the initial view controller in the method that checks for the device orientation at start-up, and then do the switching of the controllers in a call back to the UIDeviceOrientationDidChangeNotification. Finally, the actual switching with animation is done using the transitionFromViewController:toViewController:duration:options:animations:completion: method.

    #import "ContainerController.h"
    #import "LandscapeController.h"
    #import "PortraitController.h"
    
    @implementation ContainerController
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
        if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
            self.portCont = [[PortraitController alloc]initWithNibName:@"PortraitController" bundle:nil];
            self.landCont = [[LandscapeController alloc] initWithNibName:@"LandscapeController" bundle:nil];
            [self performSelectorOnMainThread:@selector(checkLaunchOrientation) withObject:nil waitUntilDone:NO];
        }
        return self;
    }
    
    
    -(void)checkLaunchOrientation {
        if ([[UIDevice currentDevice] orientation] !=0) {
    
            if (UIDevice.currentDevice.orientation == UIDeviceOrientationPortrait | UIDevice.currentDevice.orientation == UIDeviceOrientationPortraitUpsideDown){
                if ([self.currentController class] != [self.portCont class] ) {
                    self.currentController = self.portCont;
                    [self addChildViewController:self.portCont];
                    [self.view addSubview:self.portCont.view];
                }
            }else if (UIDevice.currentDevice.orientation == UIDeviceOrientationLandscapeLeft | UIDevice.currentDevice.orientation == UIDeviceOrientationLandscapeRight){
                if ([self.currentController class] != [self.landCont class] ) {
                    self.currentController = self.landCont;
                    [self addChildViewController:self.landCont];
                    [self.view addSubview:self.landCont.view];
                }
            }
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
        }else{
            [self checkLaunchOrientation];
        }
    }
    
    
    -(void)orientationChanged:(NSNotification *) aNote {
        if (UIDevice.currentDevice.orientation == UIDeviceOrientationPortrait | UIDevice.currentDevice.orientation == UIDeviceOrientationPortraitUpsideDown){
            if ([self.currentController class] != [self.portCont class] ) {
                [self addChildViewController:self.portCont];
                [self moveToNewController:self.portCont];
            }
        }else if (UIDevice.currentDevice.orientation == UIDeviceOrientationLandscapeLeft | UIDevice.currentDevice.orientation == UIDeviceOrientationLandscapeRight){
            if ([self.currentController class] != [self.landCont class] ) {
                [self addChildViewController:self.landCont];
                [self moveToNewController:self.landCont];
            }
        }
    }
    
    
    -(void)moveToNewController:(id) newController {
        [self.currentController willMoveToParentViewController:nil];
        [self transitionFromViewController:self.currentController toViewController:newController duration:.6 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{}
            completion:^(BOOL finished) {
            [self.currentController removeFromParentViewController];
            [newController didMoveToParentViewController:self];
            self.currentController = newController;
        }];
    }
    
    
    -(BOOL)shouldAutorotate {
        return YES;
    }
    
    - (NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskAll;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The issue: I have a UINavigationController as as subview of UIWindow, a rootViewController class
I have made a custom UINavigationController class so that I can have a UIAlertView
In my delegate class I have this - BluenibViewController *mvc = [[BluenibViewController alloc] init];
I have in my app class UINavigationController (with NIB) and I want to open
I have been trying to subclass the UINavigationController class for modifying things like background
I have a -(void) method in my main UITableView class, which I use to
In my mainWindow.xib, I have this setup. 1) UINavigationController containing several viewControllers. 2) UIViewController
I want to do the following : @interface UINavigationController () -(void)removeFromNavigationStack:(Class)aClass; @end and in
I have the following code inside my @interface FriendsNavController : UINavigationController class implementation. The
I have presented a UINavigationController containing UIViewController on self object with following code drawController

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.