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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:33:50+00:00 2026-06-13T23:33:50+00:00

I am on a viewController called vcA and I do this: [self.navigationController pushViewController:vcB animated:YES];

  • 0

I am on a viewController called vcA and I do this:

[self.navigationController pushViewController:vcB animated:YES];

and it works. vcB is pushed. Inside vcB’s viewDidAppear I do this:

NSArray *controllers = self.navigationController.viewControllers;

and controllers contains just one object, vcA !!!! (what?)

Why is vcB being added to the controllers array? Is there anything that can prevent that from happening?

thanks.

  • 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-13T23:33:52+00:00Added an answer on June 13, 2026 at 11:33 pm

    I banged my head on the wall for a week to solve this problem involving pushing a view controller on the navigation controller stack.

    The problem was this: I was on a navigation controlled based app and I had 3 view controllers, vA, vB and vC.

    I was pushing vB from vA using this:

    [self.navigationController pushViewController:vB animated:YES];
    

    it worked, but, when I tried to push vC from vB, the self.navigationController property of vB was nil and vB was not on the navigation controller stack. What? Yes, I pushed vB on the navigation stack and vB was not being added to it, but even so, vB was showing correctly.

    I discovered that inside vB’s viewDidLoad, self.navigationController was not nil and that vB was on the navigation controller stack, but as soon as vB’s viewDidLoad ended, vB was removed from the navigation controller stack and its navigationController property was set to nil. At that time, vB was a kind of ghost control, outside the navigation controller stack.

    I don’t need to mention that from vB I was unable to get back to vA or to push vC.

    How that happen?

    simple, I was pushing vB from inside a block… something like:

    void (^ block1)() = ^(){
    
       [self.navigationController pushViewController:vB animated:YES];
    
    };
    

    What was happening because a UIKit function (the push thing) was being executed in a block that was probably running on a thread that was not the main thread.

    The resolution to that was to wrap the push in a dispatch to the main thread, using this:

    void (^ block1)() = ^(){
    dispatch_async(dispatch_get_main_queue(),
                   ^{
                       [self.navigationController pushViewController:vB animated:YES];
                   });
    
    };  
    

    The app had another minor problem with a wrong outlet connected to a viewController, but this was the main problem. This is the kind of problem hard to spot, for being subtle. I discovered the problem when I added another button to the navigation bar and that button did not appear. So, I suspect that something involving UIKit was happening, or not happening in that case. The big problem here is that this code was not crashing, no error message, nothing, just working bad, but working.

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

Sidebar

Related Questions

What init metod is called everytime a viewcontroller is pushed to window? -viewDidLoad and
I update the UITableView's data source when viewDidAppear method is called on the ViewController
I have a viewController called HaveScrollController, and this is something like this: @interface HaveScrollController
I have a viewController called MainViewController, which has a UIButton. When tapped, this button
the viewwillappear is called in my viewcontroller but for some reason the viewdidappear is
I have a custom viewController called SourceListViewController, and I'm adding it into a UINavigationController,
I have a ViewController class called GamePlay. In GamePlay there is a nested class
Anyone know why this root View Controller's viewDidLoad is being called twice at launch?
I have one ViewController, in this i have added one Custom UIView named as
I'm setting a string in a view controller called ViewController and trying to access

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.