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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:42:30+00:00 2026-06-02T10:42:30+00:00

I have a navigation stack, with say 5 UIViewControllers. I want to remove the

  • 0

I have a navigation stack, with say 5 UIViewControllers. I want to remove the 3rd and 4th viewcontrollers in the stack on the click of a button in the 5th viewcontroller. Is it possible to do this? If so how?

  • 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-02T10:42:31+00:00Added an answer on June 2, 2026 at 10:42 am

    Use this code and enjoy:

    NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
    
    // [navigationArray removeAllObjects];    // This is just for remove all view controller from navigation stack.
    [navigationArray removeObjectAtIndex: 2];  // You can pass your index here
    self.navigationController.viewControllers = navigationArray;
    [navigationArray release];
    

    Hope this will help you.

    Edit: Swift Code

    guard let navigationController = self.navigationController else { return }
    var navigationArray = navigationController.viewControllers // To get all UIViewController stack as Array
    navigationArray.remove(at: navigationArray.count - 2) // To remove previous UIViewController
    self.navigationController?.viewControllers = navigationArray
    

    Edit: To remove all ViewController except last one -> no Back Button in the upper left corner

    guard let navigationController = self.navigationController else { return }
    var navigationArray = navigationController.viewControllers // To get all UIViewController stack as Array
    let temp = navigationArray.last
    navigationArray.removeAll()
    navigationArray.append(temp!) //To remove all previous UIViewController except the last one
    self.navigationController?.viewControllers = navigationArray
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 5 view controllers(say A,B,C,D,E) in my navigation stack. ViewController E is in
I have a navigation-based app and say my root controller A causes a viewController
Let's say you have a tab view controller on the navigation controller view stack.
I have several viewControllers controlled by a navigation controller. For example, viewController A and
I have ViewControllers A and B on the navigation stack. A does not support
I have a UIViewController that is popped from the navigation stack on iPhone and
I have a screen with a webView in my navigation controller stack and when
I have a navigation controller which also has a table view. I want to
I have a custom view controller that I push onto my navigation stack as
The root question is how many UIViewControllers can you push on the navigation stack?

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.