OGeek|极客世界-中国程序员成长平台

标题: ios - UIViewController 的委托(delegate)函数决定弹出 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 20:09
标题: ios - UIViewController 的委托(delegate)函数决定弹出

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

当我从 ViewControllerB 按下返回按钮时,我到达 ViewControllerA。

我想检查我是如何到达 ViewControllerA 的,无论是通过弹回还是作为导航堆栈的 rootViewController。



Best Answer-推荐答案


你可以给你的 backButton 一个 unwind 函数并在 View Controller 中捕获它。

@IBAction func unwindToView(unwindSegue: UIStoryboardSegue) {
    if let XControllerView = unwindSegue.sourceViewController as? XController {
        print("Coming from XControllerView")
    }
    else if let YControllerView = unwindSegue.sourceViewController as? YController {
        print("Coming from YControllerView")
    }
}

有关放松的更多信息:https://developer.apple.com/documentation/uikit/uiviewcontroller/1621473-unwind

关于ios - UIViewController 的委托(delegate)函数决定弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50330462/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4