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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:36:40+00:00 2026-05-27T09:36:40+00:00

In WWDC 2011 Session 102, Apple introduced View Controller Containment, which is the ability

  • 0

In WWDC 2011 Session 102, Apple introduced View Controller Containment, which is the ability to create custom view controller containers, analogous to UITabBarController, UINavigationController, and the like.

I watched the examples several times. There are a flurry of methods associated with this pattern, but it was a little hard to figure them out exactly. I’m going to post here what I think is going on and see if the community will confirm or disconfirm my suspicions.

Scenario 1: Moving from no parent to a new parent view controller

[vc willMoveToParentViewController:self];
[self addChildViewController:vc];
[self.view addSubview:vc.view]; // or something like this.
[vc didMoveToParentViewController:self];

Do the first two lines have to occur in the order given, or can they be reversed?

Scenario 2: Moving from a parent view controller to no parent view controller

[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];

Is it also necessary to call [vc didMoveToParentViewController:nil]? The examples in Session 102 did not do this in this scenario, but I don’t know whether that was an omission or not.

Scenario 3: Moving from one parent view controller to another

This will likely occur in the following way, because the logic in each parent view controller will be encapsulated.

// In the old parent
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];

// In the new parent
[vc willMoveToParentViewController:self];
[self addChildViewController:vc];
[self.view addSubview:vc.view];
[vc didMoveToParentViewController:self];

Questions

My main question is this: Is this how view controller containment should work, in general? Are the mechanics given above correct?

Is it necessary to call willMoveToParentViewController before calling addChildViewController? This seems like the logical order to me, but is it strictly necessary?

Is it necessary to call didMoveToParentViewController:nil after calling removeFromParentViewController?

  • 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-27T09:36:41+00:00Added an answer on May 27, 2026 at 9:36 am

    The UIViewController docs are pretty clear on when and when not to call willMove/didMove methods. Check out the “Implementing a Container View Controller” documentation.

    The docs say, that if you do not override addChildViewController, you do not have to call willMoveToParentViewController: method. However you do need to call the didMoveToParentViewController: method after the transition is complete. “Likewise, it is is the responsibility of the container view controller to call the willMoveToParentViewController: method before calling the removeFromParentViewController method. The removeFromParentViewController method calls the didMoveToParentViewController: method of the child view controller.”

    Also, there is an example worked out here and sample code here.

    Good Luck

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

Sidebar

Related Questions

WWDC 2011 and OS X Lion introduced View-Based table view for building interfaces. However,
I just watched a 2011 WWDC presentation on Implementing UIViewController Containment ( here's a
I'm studdying the WWDC session #104 for mastering UIScrollViews . I need to create
In WWDC 2011 video 309 on Storyboards. They demonstrate using a custom UITableViewCell that
At WWDC 09 in Session 304 Game Development for iPhone, Part 1 (Graphics, Audio),
Here's a slide from WWDC 2010 session 208: conn = [[NSURLConnection alloc] initWithRequest:req delegate:self
Yesterday I posed the question of why the Apple WWDC 2010 samples for the
Watching a WWDC 2011, I saw advice (but not an explanation) that one should
In the WWDC video Session 309 - Introducing Interface Builder Storyboarding the speaker adds
Does anyone know if at WWDC 2007 or 2008 there were iPhone sessions which

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.