美文网首页Swift
swift 返回指定界面的几种方法

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

作者: aggie1024 | 来源:发表于2020-08-10 15:05 被阅读0次
    // 跳转指定控制器
        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
    感谢原作者

    相关文章

      网友评论

        本文标题:swift 返回指定界面的几种方法

        本文链接:https://www.haomeiwen.com/subject/uirjdktx.html