菜鸟教程小白 发表于 2022-12-13 15:39:01

iphone - UINavigationController 嵌套在 moreViewController 中的问题


                                            <p><p>我有包含一些 UINavigationControllers 的 UITabbarMoreController。这些 UINavigationControllers 然后包含我的自定义 ViewController 。</p>

<p>所以层次结构看起来像这样:</p>

<pre><code>UITabbarController
- UINavigationController
-&gt; my custom UIViewController
- ...(other children of UITabbarController look the same)
</code></pre>

<p>在我的自定义 ViewController 中,我调用 <code></code> 应该返回一个 UINavigationController。这确实发生了,我确实得到了一个 UINavigationController,但只有当特定的 UINavigationController 不在 moreNavigationController 中时。 </p>

<p>由于我在 tabbarController 中有很多子 Controller ,所以 tabbarController 创建了一个 moreNavigationController。如果我打开 moreNavigationController 下的 ViewController 并调用 <code></code> 它会返回一个带有 UIMoreNavigationController 类的神秘对象</p>

<p>我确实需要获取作为我的 ViewController 的父级的 UINavigationController,而不是 UIMoreNavigationController。另外,我尝试使用 <code></code> 得到相同的结果。如何获得对我的 ViewController 真正最近的父级的引用?提前感谢您的帮助!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>简而言之,你不能。</p>

<p>Apple 总是尝试优化他们的代码。他们的优化之一是检查其 <code>UIMoreNavigationController</code> 列表中显示的 <code>ViewController</code> 是否属于 <code>UINavigationController</code> 类型。因为<code>UIMoreNavigationController</code> 本身就是一个UINavigationController,它不想创建另一个<code>UINavigationController</code>。它试图避免 <code>UINavigationController</code> 嵌套。 </p>

<p>当你查看 <a href="https://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIMoreNavigationController.h" rel="noreferrer noopener nofollow">UIMoreNavigationController</a> 的头文件时你会注意到它有一个变量
<code>UINavigationController* _originalNavigationController;</code> 是您创建并想要访问的原始 <code>UINavigationController</code>。不幸的是你不能因为 <code>UIMoreNavigationController</code> 是私有(private)的。 </p>

<p>解决方法(丑陋)</p>

<p>当您将 NavigationController 的引用推送到它的堆栈时,将它们传递给它的子级。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - UINavigationController 嵌套在 moreViewController 中的问题,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/11965886/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/11965886/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - UINavigationController 嵌套在 moreViewController 中的问题