菜鸟教程小白 发表于 2022-12-12 08:53:56

ios - 关闭通过 Popup 呈现的 ViewController


                                            <p><p>所以我正在使用 Storyboard 创建一个基于 ipad 食谱的应用程序。只是为了让您了解我的程序的结构,这里是 ViewController 的流程:</p>

<blockquote>
<p>ViewController --Modally--&gt; PreviewViewController --Modally--&gt;
RecipeViewController --Popup--&gt; IngredientsViewController</p>
</blockquote>

<p>所有这些都在 Storyboard中完成。我创建了 <code>IngredientsViewController</code> 并将其链接到 <code>RecipeViewController</code> 以显示为弹出窗口,效果很好。但是我希望能够以编程方式关闭 <code>IngredientsViewController</code>(因为我已经实现了语音命令功能)。问题是我似乎无法访问 <code>IngredientsViewController</code> 来关闭它。 (抱歉,我还不能发布任何图片)。</p>

<p>我正在使用以下代码以编程方式呈现 <code>IngredientsViewController</code>(来自 <code>RecipeViewController</code>):</p>

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

<p>这可以很好地显示弹出窗口,但我无法关闭它。我试图通过 ViewController 的层次结构访问它,但似乎找不到它,我认为它会位于堆栈的顶部,但显然不是?我试过这样的事情:</p>

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

<p>这又是从 <code>RecipeViewController</code> 中调用的。但这只是忽略了 <code>RecipeViewController</code> 而不是弹出窗口呈现的 <code>IngredientsViewController</code>。</p>

<p>需要说明的是<code>IngredientsViewController</code>不是<code>UIPopoverController</code>,它是在storyboard中创建的普通<code>viewController</code>,它的segue风格是popup链接到 <code>RecipeViewController</code> 中的按钮。</p>

<p>任何帮助将不胜感激。谢谢!</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><pre><code>UIPopoverController *popOver = (UIPopoverController *)self.presentedViewController;
;
</code></pre>

<p>如果您的目标 ViewController 是 <code>UIPopoverController</code></p>,这应该可以解决问题</p>
                                   
                                                <p style="font-size: 20px;">关于ios - 关闭通过 Popup 呈现的 ViewController,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/15001178/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/15001178/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 关闭通过 Popup 呈现的 ViewController