菜鸟教程小白 发表于 2022-12-11 20:09:32

ios - UIViewController 的委托(delegate)函数决定弹出


                                            <p><p>我在导航堆栈中有 3 个 ViewController,它们是 ViewControllerA、ViewControllerB 和 ViewControllerC。</p>

<p>当我从 ViewControllerB 按下返回按钮时,我到达 ViewControllerA。 </p>

<p>我想检查我是如何到达 ViewControllerA 的,无论是通过弹回还是作为导航堆栈的 rootViewController。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你可以给你的 backButton 一个 unwind 函数并在 ViewController 中捕获它。 </p>

<pre><code>@IBAction func unwindToView(unwindSegue: UIStoryboardSegue) {
    if let XControllerView = unwindSegue.sourceViewController as? XController {
      print(&#34;Coming from XControllerView&#34;)
    }
    else if let YControllerView = unwindSegue.sourceViewController as? YController {
      print(&#34;Coming from YControllerView&#34;)
    }
}
</code></pre>

<p>有关放松的更多信息:<a href="https://developer.apple.com/documentation/uikit/uiviewcontroller/1621473-unwind" rel="noreferrer noopener nofollow">https://developer.apple.com/documentation/uikit/uiviewcontroller/1621473-unwind</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UIViewController 的委托(delegate)函数决定弹出,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/50330462/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/50330462/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UIViewController 的委托(delegate)函数决定弹出