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