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 8039503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:35:30+00:00 2026-06-05T03:35:30+00:00

I bumped into a problem where UIViewController.navigationController becomes nil and I’m desperately trying to

  • 0

I bumped into a problem where UIViewController.navigationController becomes nil and I’m desperately trying to find an answer to this one.

The UINavigationController gets setup in the application delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.rootViewController = [[RootViewController alloc] initWithNibName:@"RootView" bundle:nil];

    UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
    [self.window addSubview:navigationController.view];

    [self.window makeKeyAndVisible];

    return YES;
}

When the RootViewController is appearing, the self.navigationController member is set and I can use it to hide the navigation bar, like so:

- (void)viewWillAppear:(BOOL)animated {
    NSLog( @"self = %@, self.navigationController = %@", self, self.navigationController );
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

The debug output shows values for self and self.navigationController.

When a button is clicked in this controller, self remains the same value indeed but self.navigationController is now nil:

- (IBAction)buttonClicked:(id)sender {
        NSLog( @"self = %@, self.navigationController = %@", self, self.navigationController );
        // here, self.navigationController is nil, so
        // [self.navigationController pushViewController:...] doesn't work :-(
}

I’ve seen dozens of questions regarding this problem and the answer is always that the UIViewController is not part of a UINavigationController. Since accessing the navigationController in viewWillAppear works fine, I believe something else must be going on. Do you have any pointers? I’ll happily provide more detail if necessary.

  • 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-05T03:35:31+00:00Added an answer on June 5, 2026 at 3:35 am

    Your code shows that you are only using the navigationController’s view but just pray that navigationController life is handled by some magic hand which is not the case.

    You need someone to be the explicit owner of the navigationController here.

    In fact, the following line:

    [self.window addSubview:navigationController.view];
    

    seems to indicate that what you want is for the window’s rootViewController to be navigationController:

    self.window.rootViewController = navigationController;
    

    But also, it seems that the application’s delegate is to be an owner of navigationController as well so navigationController should, in fact, be an ivar of your app’s delegate.

    In short, fix your object graph (and it will coincidentally do the extra retain you manually did and fix your bug)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to middle align an element, But I have bumped into this
During usage of NHibernate ... One strange problem that I have bumped into was
I bumped into a strange problem with one of my newest small tools. I
Hi I bumped into this problem this morning (I've already found a work around)
I've bumped into a small problem that i cant seem to find the fix
I have bumped into this problem several times on the type of input data
I just bumped into this little problem and I wanted the input of other
I bumped into this problem when I created a chart that need a axis
I'm working on a quiz for school but I've bumped into a problem. I
I have recently started programming in WPF and bumped into the following problem. I

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.