Reputation: 765
I'm trying to learn how to make child view controller and face the problem: child view controller I made for some unknown reasuns occupies the whole screen instead of view to which I add it. Here is my super-simple code:
CVCChildViewController *childViewController =
[[self storyboard] instantiateViewControllerWithIdentifier:kVCIdentifier];
[self addChildViewController:childViewController];
[self.childView addSubview:childViewController.view];
[childViewController didMoveToParentViewController:self];
And here is storyboard screen:
White UIView (childView) is subview of self.view. And I wand child view controller does not cross this childView bounds. How could I do this?
Upvotes: 0
Views: 2239
Reputation: 765
Here was my problem. "Resize View From NIB" should be unchecked for child view controller. After that it will be with correct frame. That's because this option make viewController.view.frame equal to applicationFrame by default.
Upvotes: 0
Reputation: 37512
Why you doing that programmatically? In storyboard add Container View
(instead View
) and attach your CVCChildViewController
to it. This should do the trick.
To access sub controller just provide respective IBOutlet
.
Upvotes: 0
Reputation: 995
Set your childViewController.view.bounds = self.childView.bounds
before you add as a subview.
Basically you need to set the frame of your childViewControllers view before adding it as a subview , else it would take its default height.
I hope this helps.
Cheers
Upvotes: 1