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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:59:04+00:00 2026-06-07T09:59:04+00:00

I have UIViewControllers A and B, they are allocated in AppDelegate . I need

  • 0

I have UIViewControllers A and B, they are allocated in AppDelegate. I need to apply transition to them. How to transit them without reallocating and replacing UIViews?
This code calls from my UIBarButtonItem in UINavigationController:

[UIView transitionFromView:self.view  //UIViewController A
                           toView:appDelegate.secondViewController.view //UIViewController B
                           duration:0.5 
                           options:UIViewAnimationOptionTransitionFlipFromLeft   

This method replaces UIViews in my UIViewControllers, and I can transit them back, or just don’t know how to do that. Can you tell me how to do this?

  • 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-07T09:59:06+00:00Added an answer on June 7, 2026 at 9:59 am

    If you’re in iOS 5 world and want to jump between various view controllers, you might want to pursue View Controller Containment. Or check out WWDC 2011 session 102.

    View controller containment basically assumes that you have some parent view controller which is governing the navigation between multiple child controllers. In your case, the parent view would be one with the navigation bar with the button on it.

    Update:

    If you pursue containment, you could create a parent view controller that has a nav bar with the button on it. When you load that view, you can add the first child view. Thus viewDidLoad might look like:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        // this is my model, where I store data used by my view controllers
    
        _model = [[MyModel alloc] init];
    
        // let's create our first view controller
    
        OneViewController *controller = [[OneViewController  alloc] initWithNibName:@"OneViewController"  bundle:nil];
    
        // pass it our model (obviously, `model` is a property that I've set up in my child controllers)
    
        controller.model = _model;
    
        // let's put the new child in our container and add it to the view
    
        [self addChildViewController:controller];
        [self configureChild:controller];
        [self.view addSubview:controller.view];
        [controller didMoveToParentViewController:self];
    
        // update our navigation bar title and the label of the button accordingly
    
        [self updateTitles:controller];
    }
    

    The configureChild just does final configuration. As a matter of convenience, I frequently will have a UIView that I’ve set up in IB (in this case, called childView) which I use for setting up the frame, which gets me out of the world of manually creating frames, but you can do it any way you want:

    - (void)configureChild:(UIViewController *)controller
    {
        // configure it to be the right size (I create a childView in IB that is convenient for setting the size of the views of our child view controllers)
    
        controller.view.frame = self.childView.frame;
    }
    

    This is the action if you touch the button in the navigation bar. If you’re in the first controller, set up the second controller. If you’re in the second controller, set up the first one:

    - (IBAction)barButtonTouchUpInside:(id)sender 
    {
        UIViewController *currentChildController = [self.childViewControllers objectAtIndex:0];
    
        if ([currentChildController isKindOfClass:[OneViewController class]])
        {
            TwoViewController *newChildController = [[TwoViewController alloc] initWithNibName:@"TwoViewController"  bundle:nil];
            newChildController.model = _model;
            [self transitionFrom:currentChildController To:newChildController];
        }
        else if ([currentChildController isKindOfClass:[TwoViewController class]])
        {
            OneViewController *newChildController = [[OneViewController alloc] initWithNibName:@"OneViewController"  bundle:nil];
            newChildController.model = _model;
            [self transitionFrom:currentChildController To:newChildController];
        }
        else
            NSAssert(FALSE, @"Unknown controller type");
    
    }
    

    This does the basic transition (including the various containment related calls):

    - (void)transitionFrom:(UIViewController *)oldController To:(UIViewController *)newController
    {    
        [self addChildViewController:newController];
        [self configureChild:newController];
    
        [self transitionFromViewController:oldController 
                          toViewController:newController
                                  duration:0.5
                                   options:UIViewAnimationOptionTransitionCrossDissolve
                                animations:^{
                                    [self updateTitles:newController];
                                }
                                completion:^(BOOL finished){
                                    [oldController willMoveToParentViewController:nil];
                                    [oldController removeFromParentViewController];
                                    [newController didMoveToParentViewController:self];
                                }];
    }
    

    This method just sets up the title in the nav bar in our parent view controller based upon which child is selected. It also sets up the button to reference the other controller.

    - (void)updateTitles:(UIViewController *)controller
    {
        if ([controller isKindOfClass:[OneViewController class]])
        {
            self.navigationItemTitle.title = @"First View Controller";  // current title
            self.barButton.title = @"Two";                              // title of button to take me to next controller
        }
        else if ([controller isKindOfClass:[TwoViewController class]])
        {
            self.navigationItemTitle.title = @"Second View Controller"; // current title
            self.barButton.title = @"One";                              // title of button to take me to next controller
        }
        else
            NSAssert(FALSE, @"Unknown controller type");
    }
    

    This all assumes you are going to create and destroy controllers as you jump between them. I generally do this, but use a model object to store my data so I keep whatever data I want.

    You said you don’t want to do this “without reallocating and replacing UIViews”: If so, you can also change the above code to create both child view controllers up-front and change the transition to be simply jump between them:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        // this is my model, where I store data used by my view controllers
    
        _model = [[MyModel alloc] init];
    
        // let's create our first view controller
    
        _controller0 = [[OneViewController  alloc] initWithNibName:@"OneViewController"  bundle:nil];
        _controller0.model = _model;
        [self addChildViewController:_controller0];
        [self configureChild:_controller0];
        [_controller0 didMoveToParentViewController:self];
    
        // let's create our second view controller
    
        _controller1 = [[OneViewController  alloc] initWithNibName:@"OneViewController"  bundle:nil];
        _controller1.model = _model;
        [self addChildViewController:_controller1];
        [self configureChild:_controller1];
        [_controller1 didMoveToParentViewController:self];
    
        // let's add the first view and update our navigation bar title and the label of the button accordingly
    
        _currentChildController = _controller0;
        [self.view addSubview:_currentChildController.view];
        [self updateTitles:_currentChildController];
    }
    
    - (void)transitionFrom:(UIViewController *)oldController To:(UIViewController *)newController
    {    
        [self transitionFromViewController:oldController 
                          toViewController:newController
                                  duration:0.5
                                   options:UIViewAnimationOptionTransitionCrossDissolve
                                animations:^{
                                    [self updateTitles:newController];
                                }
                                completion:^(BOOL finished){
                                    _currentChildController = newController;
                                }];
    }
    
    - (IBAction)barButtonTouchUpInside:(id)sender 
    {
        UIViewController *newChildController;
    
        if ([_currentChildController isKindOfClass:[OneViewController class]])
        {
            newChildController = _controller1;
        }
        else if ([_currentChildController isKindOfClass:[TwoViewController class]])
        {
            newChildController = _controller0;
        }
        else
            NSAssert(FALSE, @"Unknown controller type");
    
        [self transitionFrom:_currentChildController To:newChildController];
    
    }
    

    I’ve seen it both ways, so you can do whatever works for you.

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

Sidebar

Related Questions

I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those
I'm getting a bit confused with UIViews recently, I have been using them fine
I have some UIViewControllers from my old iOS4 project, they are using .xib, created
I have 2 UIViewControllers(A,B). A is set as the delegate for B and then
I have a multi view application with individual UIViewControllers and xibs. I have one
In one of my UIViewControllers , I have a UITableView , which only has
All my views/pages in apps so far have been full screen UIViewControllers that i
A few UIViewControllers in my app that need to register with a provider class
I have a UIViewController whose view has a custom subview. This custom subview needs
I know nib files are serialized objects and they have owner, outlets to make

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.