我的内部有ContainerView
和ViewController
。然后,当用户点击按钮时,我隐藏了这个ContainerView
(myContainerView.hidden = true
),但ViewController
继续工作,导致冻结。如何隐藏ContainerView
和停止 ViewController
,以触发viewWillDisappear
方法。我不需要每次都杀掉它。
当你更改标签时,同样的行为有UITabBarController
,它只是停止了控制器。
答案 0 :(得分:1)
调用我们删除的标准函数 removeFromParentViewController Container层次结构中的当前Detail Controller。当这个 函数被调用,函数 didMoveToParentViewController 是 在详细控制器上使用nil作为参数自动调用。
再次添加
- (void)presentDetailController:(UIViewController*)detailVC{
//0. Remove the current Detail View Controller showed
if(self.currentDetailViewController){
[self removeCurrentDetailViewController];
}
//1. Add the detail controller as child of the container
[self addChildViewController:detailVC];
//2. Define the detail controller's view size
detailVC.view.frame = [self frameForDetailController];
//3. Add the Detail controller's view to the Container's detail view and save a reference to the detail View Controller
[self.detailView addSubview:detailVC.view];
self.currentDetailViewController = detailVC;
//4. Complete the add flow calling the function didMoveToParentViewController
[detailVC didMoveToParentViewController:self];
}