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

  • Home
  • SEARCH
  • 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 213257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:15:42+00:00 2026-05-11T18:15:42+00:00

In short: I want to have two fullscreen views, where I can switch between

  • 0

In short: I want to have two fullscreen views, where I can switch between view A and view B. I know I could just use an Tab Bar Controller, but I dont want to. I want to see how this is done by hand, for learning what’s going on under the hood.

I have an UIViewController that acts as an root controller:

@interface MyRootController : UIViewController {
    IBOutlet UIView *contentView;
}
@property(nonatomic, retain) UIView *contentView;

@end

The contentView is hooked up to an UIView which I added as an subview to the “view” of the Nib. This has green color and I see it fullscreen. Works fine.

Then, I created two other View Controllers pretty much the same way. ViewControllerA and ViewControllerB. ViewControllerA has a blue background, ViewControllerB has a black background. Just to see which one is active.

So, in the implementation of myRootController, I do this:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];

    ViewControllerA *vcA = [[ViewControllerA alloc] initWithNib];
    [self.contentView addSubview:vcA.view];

    [cvA release];
}

By the way, the -initWithNib method looks like this:

- (id)initWithNib { // Load the view nib
    if (self = [super initWithNibName:@"ViewA" bundle:nil]) {
        // do ivar initialization here, if needed
    }
    return self;
}

That works. I see the view from ViewControllerA when I start the app. But now the big question is: A View Controller typically has all those methods like:

  • (void)viewWillAppear:(BOOL)animated;
  • (void)viewDidDisappear:(BOOL)animated;
  • (void)viewDidLoad;

…and so on. Who or what, or how would those methods be called if I do it “my” way without a tab bar controller? I mean: If I allocate that ViewController’s class and the view get’s visible, would I have to take care about calling those methods? How does it know that viewWillAppear, viewDidDisappear, or viewDidLoad? I believe that the Tab Bar Controller has all this “cleverness” under the hood. Or am I wrong?

UPDATE: I’ve tested it. If I release the view controller (for example: ViewControllerA), I will get no log message on viewDidDisappear. Only when allocating and initializing the ViewControllerA, I get an viewDidLoad. But that’s it. So all signs stand for the cleverness of UITabBarController now 😉 and I have to figure out how to replicate that, right?

  • 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-11T18:15:42+00:00Added an answer on May 11, 2026 at 6:15 pm

    You can begin from the simplest removeFromSuperview/insertSubview and add code to it little by little.

    
    //SwitchViewController.h
    #import 
    @class BlueViewController;
    @class YellowViewController;
    
    @interface SwitchViewController : UIViewController {
        IBOutlet BlueViewController *blueViewController;
        IBOutlet YellowViewController *yellowViewController;
    }
    - (IBAction)switchViews:(id)sender;
    @property (nonatomic, retain) BlueViewController *blueViewController;
    @property (nonatomic, retain) YellowViewController *yellowViewController;
    @end
    
    
    //1. remove yellow view and insert blue view
    - (IBAction)switchViews:(id)sender {
        if(self.blueViewController.view.superview == nil)
        {
            [yellowViewController.view removeFromSuperview];
            [self.view insertSubview:blueViewController.view atIndex:0];
        }
    }
    
    //2. appear=insert, disappear=remove
    if(blueViewController.view.superview == nil)
    {
        [blueViewController viewWillAppear:YES];
        [yellowViewController viewWillDisappear:YES];
    
        [yellowViewController.view removeFromSuperview];
        [self.view insertSubview:self.blueViewController.view atIndex:0];
    
        [yellowViewController viewDidDisappear:YES];
        [blueViewController viewDidAppear:YES];
    }
    
    //3. now add animation
    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    //blue view will appear by flipping from right
    if(blueViewController.view.superview == nil)
    {
        [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight 
                                forView:self.view cache:YES];
    
        [blueViewController viewWillAppear:YES];
        [yellowViewController viewWillDisappear:YES];
    
        [yellowViewController.view removeFromSuperview];
        [self.view insertSubview:self.blueViewController.view atIndex:0];
    
        [yellowViewController viewDidDisappear:YES];
        [blueViewController viewDidAppear:YES];
    }
    [UIView commitAnimations];
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which plays two sounds. I want the user to know
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can
I am coding a messaging system and I don't want to have short IDs
I have a short question. I want do put this \tssr>&\8=f23' into a String
With no developer interaction you can have a view resize itself to support an
At work I have two XP PCs. On one, I can click with the
I have a 16 bit luminance value stored in two bytes, and I want
I have two activities. Home activity contain a list view with two buttons named
SHORT DESCRIPTION: For example we have two pages. The second page contain block which
I have two applications and want them to share their sessions. This is trivial,

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.