在ARC情況下,當子控制器無強指針指向時就會被自動銷毀。
[a.view ?addSubview:b.view];
[a ?addChildViewController:b];
添加一個 child view controller
UIViewController *vc = [UIViewController new];
[self addChildViewController:vc]; // 把vc作為當前viewcontrller的子控制器
// config vc.
[self.view addSubview:vc.view]; // 把vc的view添加到父控制器上面
[vc didMoveToParentViewController:self];? // 子vc被通知現(xiàn)在有了一個父控制器
移除一個 child view controller
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview];
[vc removeFromParentViewController];
上面便是正確建立/解除父子試圖控制器的正確做法