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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:05:21+00:00 2026-05-25T18:05:21+00:00

When I push cancel button in the third view, I want to go back

  • 0

When I push cancel button in the third view, I want to go back to the first view directly.
I also want to remove the second view.
How can I do that?

This is the code.

// this part is in the first view.
self.second = [SecondController alloc] init];
[self.view addSubview:second.view];

// this part is in the second view.
ThirdController *thirdController = [[ThirdController alloc] initWithStyle:UITableViewStyleGrouped];             
self.navigationController = [UINavigationController alloc] initWithRootViewController:thirdController];
[self.view addSubview:navigationController.view];

// this part is in the third view.
- (void)cancel {
    [self.view removeFromSuperview]; // this only goes to the second view.
}

EDIT:
Can I use popToViewController in called contoller? My app crashes.
I thought popToViewController can be used only in calling controller.
And popToViewController is used when it was pushed.
I did add not push.

  • 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-05-25T18:05:21+00:00Added an answer on May 25, 2026 at 6:05 pm

    popToViewController:animated: is a UINavigationController method that you use when popping view controllers off the navigation controller stack. It doesn’t fit for this scenario.

    This user is adding subviews, not pushing them on a navigation controller stack.

    As a note, it appears as a matter of design you should be using a navigation controller with the first view as the root controller, then the second pushed on the stack, and the third pushed on the stack. Then all you have to do is [self.navigationController popToRootViewControllerAnimated:YES].

    I think this will work if you want to keep your current architecture:

    // this part is in the third view.
    - (void)cancel {
        // remove the second view (self.view.superview) from the first view
        [self.view.superview removeFromSuperView];
        // can't recall, possibly you still need to remove the third view, but i think removing the superview will do it.
        // [self.view removeFromSuperView];
    }
    

    If you prefer to try the UINavigationController route, then the easiest path is to create a new project in Xcode and select the type for a Navigation-Based Application or a Master-Detail Application. This will create a UINavigationController in a nib and add it to your window. You can then set the root view controller in Interface Builder to your FirstViewController class.

    If you prefer to create the UINavigationController in code, then that is also possible. I show that below, along with the rest of the code you need, regardless of whether you create your UINavigationController in a nib in IB or in code.

    I also recommend reading the View Controller Programming Guide for iOS.

    In your app delegate or some other code:

    -(void)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions [
        // I would recommend setting up the UINavigationController and FirstViewController as IBOutlets in your nib, but it can be done in code.
        FirstViewController* fvc = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil];
        UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:fvc];
    
        [window addSubView:navController.view];
        [window makeKeyAndVisible];
    
        [fvc release];
        [navController release];
    }
    

    In the first view controller:

    SecondViewController* svc = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:nil];
    [self.navigationController pushViewController:svc animated:YES];
    [svc release];
    

    In the second view controller:

    ThirdViewController* tvc = [[ThirdViewController alloc] initWithNibName:@"ThirdView" bundle:nil];
    [self.navigationController pushViewController:tvc animated:YES];
    [tvc release];
    

    In the third view controller:

    -(void)cancel {
        // returns to the first view controller
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to push root view controller. Why doesn't this code work? RootController *rootController
I want to use push notification in my app.i want to know that do
I hope that receiving a push-notification (c2dm) reception display Notification. This Notification start, whith
In my app, I am adding push notification support. In that can I show
Read about Server push here . I want to push data to client from
I have a UINavigationController with a root view controller and then I push a
1/I don't want to notify user if this one is already running my app
I want to skip 2 tr in the table with 2 different classes. first
how we can maintain push notification for hundreds of devices? do we need to
I've had a lot of users complain that the little i info button is

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.