Container views in iOS

I wanted to use the Container View to launch another view controller, but I cannot find any information on how to program it. I can do this from the user interface, but if I want to create it using koi and associate it with a UIviewController, how can I do this? Does it behave like a normal UIview?

+4
source share
2 answers

If I follow your question, you are asking how to use controller content restriction in code. I would suggest checking Creating custom container controllers in the View Controller Programming Guide, which shows the code for this, including adding a child view controller:

[self addChildViewController:content]; // 1 content.view.frame = [self frameForContentController]; // 2 [self.view addSubview:self.currentClientView]; [content didMoveToParentViewController:self]; // 3 

When using child view controllers (at least those that do not occupy the entire screen), it is useful to have a UIView on the parent view controller's view, which defines the boundaries of the child view's controller. This greatly simplifies the set of tasks. The code snippet above assumes that the subview is called frameForContentController .

Or delete one (in this code snippet, content is a UIViewController * that refers to the remote child controller):

 [content willMoveToParentViewController:nil]; // 1 [content.view removeFromSuperview]; // 2 [content removeFromParentViewController]; // 3 

And if you want to replace the child controller with another child controller:

 - (void) cycleFromViewController: (UIViewController*) oldC toViewController: (UIViewController*) newC { [oldC willMoveToParentViewController:nil]; // 1 [self addChildViewController:newC]; newC.view.frame = [self newViewStartFrame]; // 2 CGRect endFrame = [self oldViewEndFrame]; [self transitionFromViewController: oldC toViewController: newC // 3 duration: 0.25 options:0 animations:^{ newC.view.frame = oldC.view.frame; // 4 oldC.view.frame = endFrame; } completion:^(BOOL finished) { [oldC removeFromParentViewController]; // 5 [newC didMoveToParentViewController:self]; }]; } 

I also suggest checking out WWDC 2011 - Implementing the UIViewController Containment .

+11
source

Just use a regular UIView that belongs to the parent VC. Create a child VC and add it to the parent VC using addChildViewController: and then add the child VC view to the container view as the subview method addSubview: in the VC viewDidLoad .

0
source

All Articles