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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:45:08+00:00 2026-05-25T06:45:08+00:00

I am trying to remove two viewcontrollers (that have been added on top of

  • 0

I am trying to remove two viewcontrollers (that have been added on top of each other) with one method. I have made the views in interfacebuilder. they all have their own .h and .m files to go with it.

Scenario I am in:

I have a main menu which has the view2 header file imported. In a method I add the second view on top of the superview like so

 view2ViewController * view2 = [[view2ViewController alloc]      initWithNibName:@"view2ViewController" bundle:nil];
 [self.view addSubview:view2.view];

then in view 2 I have added the view 3 header file so i can add view 3 as a subview ontop of view2. i have another method which is connected again to interface builder to a UIButton so upon button press a method gets called in view2 which adds view 3 on top in exactly the same way like so:

 view3ViewController * view3 = [[view3ViewController alloc]      initWithNibName:@"view3ViewController" bundle:nil];
  [self.view addSubview:view3.view];

What im trying to solve: I have a button in view 3 which should remove view 3…. and then it should also remove view 2 aswell so the main screen is visible.

How can this be achieved?

What I have so far:

  [self.view removeFromSuperview];

This however only removes View 3… but leaves view 2 in place.

What needs to be modified so that i can remove view 2 as well??

Any help is appreciated.

  • 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-25T06:45:09+00:00Added an answer on May 25, 2026 at 6:45 am

    Actually the way you have added any view is the same way you’ll remove that view. Suppose, you added the view by pushing it into the navigation controller like this

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

    then you’ll need to write this into yourViewController.m file

        //inYourViewController.m file
        [self.navigationController popViewControllerAnimated:YES];  
    

    NEW EDIT :

    Ok, so assuming you did presentModalViewController then do this.

    Now, your second question where you want to go to view1 instead of view2. Make a boolean variable in your AppDelegate. Set it when you press the done button in View3.

        //inYourAppDelegate.h
        BOOL doneBtnClicked = NO;
    
        //inYourViewController3.m
        - (IBAction) doneBtnPressed : (id) sender
        {
                //your code
                yourAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
                appDelegate.doneBtnClicked = YES;
      >>CHANGE THIS     [self.view removeFromSuperview];
        }
    

    Now, in your view2, in the viewWillAppear method

        - (void) viewWillAppear:(BOOL)animated
        {
            [super viewWillAppear:animated];
                //your code
                yourAppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
                if(appDelegate.doneBtnClicked)
                {
                         appDelegate.doneBtnClicked = NO;
         >>AND THIS      [self.view removeFromSuperview];
                } 
        }
    

    HOWEVER, what you want to do is very easily possible with the help of UINavigationController.I suggest you to do with the help of navigation, as it would really become easy in the terms of memory management and moreover Navigation Controller is for this purpose only.

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

Sidebar

Related Questions

I am trying to remove two viewcontrollers (that have been added on top of
I am trying to compare two strings and remove any characters that appear in
I'm trying to join one table, with two other tables, using a single column
Hi I am trying to remove all numbers that are divisible by two from
I'm trying to remove the comma that occurs in [,{ I've tried two things
I am trying to remove a ManyToMany relationship inside Doctrine 2. I have two
I have two lists of type SelectListItem. I am trying remove the items in
I have two lists containing unicode strings. I'm trying to remove every element from
I'm trying to remove two parts of two strings of an array which is
I'm trying to use Unix cut to remove the first two fields per line.

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.