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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:13:33+00:00 2026-06-05T07:13:33+00:00

I have an iphone application that uses a navigation controller. In that controller I

  • 0

I have an iphone application that uses a navigation controller. In that controller I push some views. In some cases I want to “clear” the views stack, leave only the rootViewController of the navigation controller in the stack and push another viewController I have.

Can someone give me an example on how to do this? I don’t see any method that clears the stack.


Answer 1:
I have tried to put in button Action the following code:

[self.navigationController popToRootViewControllerAnimated:NO]; 

 do some stuff here to prepare for the push.

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

but it only pops to the roorController. It doesn’t push the other viewController I want.

  • 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-05T07:13:34+00:00Added an answer on June 5, 2026 at 7:13 am

    The following code will allow the user to drill down a view hierarchy, and at the press of a button, pop back to the root view controller and push a new view.

    DetailViewController.m ~ the view controller from which to clear the navigation stack:

    - (IBAction)buttonPressed:(id)sender {
        [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"popBack" object:nil]];
    }
    

    The above code makes a call to NSNotificationCenter, posting a notification that the RootViewController can react to when heard. But first, the RootViewController must register to receive the notification.

    RootViewController.m

    - (void)viewDidLoad
    {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushViews) name:@"popBack" object:nil];
        [super viewDidLoad];
    }
    

    Next, the RootViewController must set up the referenced selector -pushViews.

    - (void)pushViews {
         //Pop back to the root view controller
         [self.navigationController popToRootViewControllerAnimated:NO];
    
         //Allocate and init the new view controller to push to
         NewViewController *newVC = [[NewViewController alloc] init];
    
         //Push the new view controller
         [self.navigationController pushViewController:newVC animated:YES];
    }
    

    Be sure that when you call -popToRootViewControllerAnimated:, you specify NO for animation. Enabling animation causes hiccups in the navigation bar animation and confuses the system. The above code, when called, will clear the navigation stack, leaving only the RootViewController, and then adding the NewViewController.

    The reason your initial code was not fully executing was because after calling -popToRootViewController: from your DetailViewController, the RootViewController’s methods occupied the main thread, and the DetailViewController was released. Thus, no further code was run from that view controller. Using the code above, the navigation stack is popping back to the same view controller that is being loaded.

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

Sidebar

Related Questions

I have an iPhone application I've been using for some time that uses ASIHTTPRequest
I have an iPhone application that uses a timer and at every time interval
I have an iPhone application that uses a sqlite3 database for saving data and
I have an iPhone application that uses a set of plists to load the
I'm doing an iPhone application which uses a navigation control to browse through some
I have an Xcode project (for an iPhone application) that uses cocos2d. I have
I have an iPhone application that loads succesive views in a framework based on
I have an iPhone iOS4.1 application that uses localized strings. I have just started
I'm developing an iPhone application that uses the iPod library to play some songs.
Question 1 I want to make IPhone application that uses OpenID for authentication. 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.