简体   繁体   中英

Why need to add subview again after add child view controller?

Since I hava a parent view controller and a child one,
parent view controller is something like a container controller that apple doc said,
then do

[parentVC addChildViewController:childVC];
childVC.view.frame = SOMEFRAME;

but now childVC has not been seen in the screen;
must I add code below?

[parentVC.view addSubview:childVC.view];//is a must? any code can replace?  

--
At my sight,container is container,when I had added a childVC in,it's view should add itself, or some method can do that?.

UIWindow has a property of "rootViewController",when set it,the new view will be added automatically,I think this is what I want.

I need some advices.thanks.

It's a simple matter of control. Often you want to have a child view controller, but it's view is a subview of one of your subviews, not simply a subview of the "top level" view property of the container view controller.

Essentially, the framework chooses to let you decide, and does not enforce that a contained view controller's view must be a first-generation decedent of it's parent view controller. It's completely up to you; the hierarchy of ViewControllers and Views do not need to have perfect generational parity.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM