iOS路由viewDidAppear到子视图控制器? [英] iOS routing viewDidAppear to child view controllers?

查看:127
本文介绍了iOS路由viewDidAppear到子视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向父视图控制器添加一个子视图控制器,一切都按预期工作,除了子视图控制器没有触发其通常的回调。例如,从未调用像viewWillAppear(动画)这样的东西。我调查了一下,并认为这可能是因为我没有在子视图控制器上分别将它添加到父视图之前和之后调用willMoveToParentViewController和didMoveToParentViewController。不幸的是,修复没有任何区别。有谁知道如何连接它,以便当我执行addChildViewController和removeChildViewController时,会触发常规回调?添加childViewController后,我还将其视图作为子视图添加到父视图控制器的视图中。在任何一点(addChildViewController& addSubview)都会调用子视图控制器的viewWillAppear(动画)等方法...

I'm adding a child view controller to a parent view controller, and everything works as expected, except that child view controller isn't having its usual callbacks triggered. eg, things like viewWillAppear(animated) is never called. I looked into it and thought it may be because I wasn't calling willMoveToParentViewController and didMoveToParentViewController on the child view controller before and after adding it to the parent, respectively. Unfortunately, fixing that has made no difference. Does anyone know how I can wire this up so that when I do addChildViewController and removeChildViewController the regular callbacks are triggered? After adding the childViewController, I also add its view as a subview to the parent view controller's view. At neither point (addChildViewController & addSubview) does the child view controller's viewWillAppear(animated), etc methods get called...

Nick

推荐答案

viewWillAppear viewDIdAppear

viewWillDisappear viewDidDisappear

也许这个方法没有被调用,因为你在显示主视图控制器之前添加了子控制器视图,因此你的主视图本身不在hiererchy本身?

Maybe this methods not called because you are adding sub-controller view before displaying main view controller and, therefore your main view is not in view hiererchy itself?

当您的主视图控制器出现或消失时,您应该在相应的方法中为子项调用此方法。

When your main view controller appears or disappears you should call this methods for childs in corresponding methods.

这篇关于iOS路由viewDidAppear到子视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆