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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:34:14+00:00 2026-06-01T08:34:14+00:00

When implementing UIViewController containment, what is the correct order of the following messages I

  • 0

When implementing UIViewController containment, what is the correct order of the following messages I have to send, when exchanging one child controller with another?

Is it as below, or is my order incorrect? Am I missing messages?

  • Add new child controller to current controller: addChildViewController:
  • Add subview of new child controller to current controller’s view: addSubview:
  • Run some fancy transition from old view to new view.
  • Inform new child controller that is was added to another controller: didMoveToParentViewController:
  • Remove the previous controller’s view from its superview: removeFromSuperview:
  • Remove the previous child controller from its parent: removeFromParentViewController:

EDIT:
I have to annotate that the above only becomes an issue of you are not using UIViewController’s transition methods but rather want to add the new view manually.

  • 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-01T08:34:15+00:00Added an answer on June 1, 2026 at 8:34 am

    Okay, figured it out. It’s all in the docs but I find it pretty well hidden. I’ll split it up into three cases because I think it might help others. Why am I making it so difficult instead of using [UIViewController transitionFromViewController:toViewController:duration:options:animations:completion] ? The answer is that you can only use the transition method if there is already an existing view controller. If you want to transition from “no controller” to some controller or vice versa, the above method will throw an exception.

    Case 1: Both controllers are equal – that includes that both are null

    • Do nothing, we already have what we want on screen. 🙂

    Case 2: The old controller is NULL, and the new controller is not NULL. Just add the new controller.

    • Send addChildViewController to new controller – this will trigger an implicit willMoveToParentViewController
    • Make the new view the size you want
    • Insert the child controller’s view into this controller’s view hierarchy: addSubview
    • Inform child controller that it was added as a child by sending it: didMoveToParentViewController

    Case 3: old controller is not NULL and new controller is not NULL. Run a transition between controllers.

    • Adjust new view’s frame/bounds.
    • Send addChildViewController to new controller – this will trigger an implicit willMoveToParentViewController
    • Send the old controller willMoveToParentViewController and pass it nil as the new parent
    • Add the new subview to your view
    • Run your custom transition between the old and the new view using UIView's animations.
    • In the animation end delegate, send didMoveToParentViewController to the new controller.
    • Remove the view of the old controller from its superview.
    • Send removeFromParentViewController to the old controller – this will trigger an implicit didMoveToParentViewController
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When implementing Quicksort, one of the things you have to do is to choose
I just watched a 2011 WWDC presentation on Implementing UIViewController Containment ( here's a
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
Implementing a low pass FIR filter, when should one use FFT and IFFT instead
When implementing move constructors and move assignment operators, one often writes code like this:
I'm using a custom UITableViewController (myTblController) as a member variable in another UIViewController (MainViewController).
I'm implementing didReceiveMemoryWarning in a subclass of UIViewController. My code looks something like the
I have: @interface SuperClass : UIViewController <UITableViewDelegate,UITableViewDataSource> And then @interface SubClass : SuperClass This
Suppose I have a UIViewController subclass that takes care of some UIViews. These UIViews
I'm a new in iOS, and I have trouble in implementing @protocol so sorry

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.