Container View Controller Examples

Objective CIosUiviewcontrollerIos5

Objective C Problem Overview


Can anyone point me to any good examples of creating a Custom View Controller as a Container View Controller? The only documentation I can find is a couple of paragraphs in the UIViewController Class Reference. I feel I need a little more information than that and an example implementation would be nice. Google has turned up nothing at all.

I am specifically interested in the method:

transitionFromViewController:toViewController:duration:options:animations:completion:

Objective C Solutions


Solution 1 - Objective C

The best thing I have found so far is the WWDC 2011 Session Video Session 102 - Implementing UIViewController Containment.

Solution 2 - Objective C

Solution 3 - Objective C

- (void)viewDidLoad{
    [super viewDidLoad];

    // I put self in a Navigation VC so we can use its right navigationbar 
    // item for triggering the transition
    self.navigationItem.rightBarButtonItem = 
     [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit 
                                                    target:self 
                                                    action:@selector(button:)] 
                                                                  autorelease];

    // create test1 and test2 instance (subclass UIViewController and 
    // also need to define their own nibs)
    vc1 = [[test1 alloc]initWithNibName:@"test1" bundle:nil];
    vc2 = [[test2 alloc]initWithNibName:@"test2" bundle:nil];

    //add to the container vc which is self    
    [self addChildViewController:vc1];
    [self addChildViewController:vc2];

    //the entry view (will be removed from it superview later by the api)
    [self.view addSubview:vc1.view];
}

this IBAction triggers the transition between two VCs:

-(IBAction)button:(id)sender {
    [self transitionFromViewController:vc1 
                      toViewController:vc2 
                              duration:0.5    
                               options:UIViewAnimationOptionTransitionCurlDown 
                            animations:nil 
                            completion:nil];
}

Solution 4 - Objective C

Solution 5 - Objective C

Solution 6 - Objective C

don't know if this is a "good" example, but you can get a free Container ViewController from https://bitbucket.org/javieralonso/jaacordeonviewcontroller/overview

It's a full accordion metaphor container view controller

Solution 7 - Objective C

These are my favorite (iOS7-ready) tutorial / examples on the subject (all three have source code available on github):

View Controller Containment

Custom Container View Controller Transitions

Interactive Custom Container View Controller Transitions

And then, of course, Apple offers a whole write-up on the subject which I find invaluable:

Creating Custom Container View Controllers

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUndistractionView Question on Stackoverflow
Solution 1 - Objective ChypercryptView Answer on Stackoverflow
Solution 2 - Objective CJosephHView Answer on Stackoverflow
Solution 3 - Objective CsonnywangView Answer on Stackoverflow
Solution 4 - Objective CYuri SolodkinView Answer on Stackoverflow
Solution 5 - Objective CRui PeresView Answer on Stackoverflow
Solution 6 - Objective CjavieralogView Answer on Stackoverflow
Solution 7 - Objective CradiovisualView Answer on Stackoverflow