UINavigationController的addChildViewController和topViewController之间的交互 [英] Interplay between UINavigationController’s addChildViewController and topViewController

查看:532
本文介绍了UINavigationController的addChildViewController和topViewController之间的交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像模态视图控制器,我需要显示在我的其他视图控制器。我不使用常规模态控制器功能( presentViewController:和朋友),因为我需要更好的控制过程。相反,我使用视图控制器包含功能( addChildViewController:方法组)。

I have something like a modal view controller that I need to display above my other view controllers. I’m not using the regular modal controller feature (presentViewController: and friends), since I need better control over the process. Instead I am using the view controller containment feature (the addChildViewController: method group).

代码相当简单。当我需要呈现模态视图控制器时,我将它作为子视图添加到视图控制器层次结构,一切正常工作。一个小的捕获是常规视图控制器被包裹在导航控制器中。因此,我必须添加模态控制器作为导航控制器的孩子,否则将被导航栏和工具栏覆盖。

The containment feature makes the code fairly straightforward. When I need to present the "modal" view controller, I add it as a child to the view controller hierarchy and everything works as expected. One small catch is that the regular view controllers are wrapped in a navigation controller. Therefore I have to add the modal controller as a child of the navigation controller, otherwise it would be covered by the navigation bar and toolbar.

现在的问题是调用 addChildViewController:在一个导航控制器上也设置新的控制器为 topViewController ,就好像控制器是使用正常 pushViewController:方法。这意味着在显示模态控制器时,它下面的常规控制器不会收到外观和旋转回调。

Now the problem is that calling addChildViewController: on a navigation controller also sets the new controller as the topViewController, as if the controller was pushed using the regular pushViewController: method. This means that while the modal controller is displayed, the regular controller underneath it does not receive the appearance and rotation callbacks.

这感觉像一个错误, ?

This feels like a bug, or am I missing something?

推荐答案

我在 addChildViewController的文档中错过了这一句: / p>

I missed this sentence in the documentation for addChildViewController:


此方法只能通过
自定义容器视图控制器的实现来调用。

This method is only intended to be called by an implementation of a custom container view controller.

所以我想这是我的错,这种情况根本不支持。因为它是非常方便的设计任何模态的东西作为普通视图控制器,并将它们连接到层次结构,像正确的一等公民。我可能需要自己重写导航控制器,以具有内置的支持。

So I guess it’s my fault and this scenario is simply not supported. Which sucks, because it’s very convenient to design whatever modal things as regular view controllers and connect them to the hierarchy like proper first-class citizens. I would probably have to rewrite the navigation controller on my own to have built-in support for this.

这篇关于UINavigationController的addChildViewController和topViewController之间的交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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