我有一个类似于模态视图 Controller 的东西,我需要在其他 View Controller 上方显示它。我没有使用常规模式 Controller 功能(presentViewController: 和 friend ),因为我需要更好地控制流程。相反,我正在使用 View Controller 包含功能(addChildViewController: 方法组)。
包含特性使代码相当简单。当我需要呈现“模态” View Controller 时,我将它作为 subview Controller 添加到 View Controller 层次结构中,一切都按预期进行。一个小问题是常规 View Controller 包含在导航 Controller 中。因此,我必须将模态 Controller 添加为导航 Controller 的子级,否则它会被导航栏和工具栏覆盖。
现在的问题是,在导航 Controller 上调用 addChildViewController: 也会将新 Controller 设置为 topViewController,就像使用常规 推送 Controller 一样pushViewController: 方法。这意味着当模态 Controller 显示时,其下方的常规 Controller 不会收到外观和旋转回调。
这感觉像是一个错误,还是我遗漏了什么?
最佳答案
我遇到了同样的问题。我通过编写自己的自定义 View Controller 解决了这个问题,其中包含一个 UINavigationController(通过 addChildViewController: 添加),然后将 UINavigationController 公开为只读属性.然后,您可以将模态视图 Controller 添加为新自定义 View Controller 的子级,而不是 UINavigationController
关于objective-c - UINavigationController 的 addChildViewController 和 topViewController 之间的相互作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10512911/