swift 返回指定界面的几种方法

// 跳转指定控制器
    func jumpDesignatedController() {
        
        // 方法一(跳转指定控制器)
        let mineVC = MyAcountAuthViewController()
        var targetVC : UIViewController!
        for controller in self.navigationController!.viewControllers {
            if controller.isKind(of: mineVC.classForCoder) {
                targetVC = controller
            }
        }
        if targetVC != nil {
            self.navigationController?.popToViewController(targetVC, animated: true)
        }
        
        // 方法二(跳转根控制器)
        self.navigationController?.popToRootViewController(animated: true)
        
        // 方法三(返回到根界面的某个控制器)
        self.navigationController?.tabBarController?.hidesBottomBarWhenPushed = false
        self.navigationController?.tabBarController?.selectedIndex = 0 // (第一个控制器)
        self.navigationController?.popToRootViewController(animated: true)
        // 方法四(返回两级界面)
        if (self.navigationController?.viewControllers.count)! >= 2 {
            guard let vc = self.navigationController?.viewControllers[1] else { return }
            self.navigationController?.popToViewController(vc, animated: true)
        }
    }

原地址:https://www.jianshu.com/p/f0e69f325809
感谢原作者

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容