willMoveToParentViewController: 和 didMoveToParentViewController: 到底是做什么的? [英] What exactly willMoveToParentViewController: and didMoveToParentViewController: do?

查看:18
本文介绍了willMoveToParentViewController: 和 didMoveToParentViewController: 到底是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道从 iOS5 和新的 UIViewController 包含方法开始,您应该将这些方法与 addChildViewController:removeFromParentViewController: 和转换方法一起调用.我也知道在三种情况下调用它们的正确顺序.我不知道这些方法到底是做什么的?

I know that starting with iOS5 and the new UIViewController containment methods, you are supposed to call these methods together with addChildViewController:, removeFromParentViewController: and the transition method. I also know the proper order of calling them in the three scenarios. What I don't know is what exactly these methods do?

如果这些只是 UIViewController 子类的覆盖点,我想我们不需要在覆盖时调用 super.如果我在删除视图控制器或 didMoveToParentViewController: self 之前不调用 willMoveToParentViewController: nil 会/会出现什么问题?

If these were merely override points for subclasses of UIViewController I guess we wouldn't be required to call super when overriding. What can/will go wrong if I don't call willMoveToParentViewController: nil before removing a view controller or didMoveToParentViewController: self?

推荐答案

除了上面所说的,他们确实调用了一些委托方法:

In addition to what has been said, they do call some delegate methods:

addChildViewController 调用 [child willMoveToParentViewController:self]

removeFromParentViewController: 调用 [child didMoveToParentViewController:nil]

此外,他们还修改了 childViewControllers 属性,该属性包含一组子视图控制器.

Also, they modify the childViewControllers property, which holds an array of child view controllers.

这篇关于willMoveToParentViewController: 和 didMoveToParentViewController: 到底是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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