菜鸟教程小白 发表于 2022-12-11 17:26:35

ios - UIStoryboard 引用和 Root View Controller


                                            <p><p>我有一个“主” Storyboard,在这个 Storyboard内我有一个 Storyboard引用实体,它链接到另一个 Storyboard“登录”。我注意到,当我尝试使用以下内容访问当前屏幕上的 View 时:</p>

<pre><code>[[[delegate]window]rootViewController]
</code></pre>

<p>它返回了“主” Storyboard 上的 View ,但如果我尝试在此 View 上推送 UIAlertController,我会收到以下错误:</p>

<pre><code>Warning: Attempt to present &lt;UIAlertController: 0x1839a000&gt; on &lt;ViewController: 0x17633ad0&gt; whose view is not in the window hierarchy!
</code></pre>

<p>是否有原因我不能将此 View 推到顶部,如果不是,我如何从“登录” Storyboard 中获取当前显示的实际 uiviewcontroller?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>如果您从 <code>viewDidload</code> 呈现 <code>UIAlertController</code> 那么它可能会发生这样的情况,因为当时正在加载 View 时,它在完全加载之前不在 Windows 层次结构中。 </p>

<p>第二件事你必须在最顶部的 ViewController 上显示 <code>UIAlertController</code>,例如,</p>

<pre><code> ;
</code></pre>

<p>不在 Windows rootViewController 上。所以,这取决于你如何做到这一点。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UIStoryboard 引用和 Root ViewController ,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39327574/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39327574/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UIStoryboard 引用和 Root View Controller