swift 不同tabbar 切换

        let target = self.navigationController?.viewControllers.first(where: { $0.isKind(of: MineViewController.self) })
        guard let targetViewController = target as? MineViewController else {
            navigationController?.pushViewController(MineViewController(), animated: true)
            return
        }
        // 如果targetViewController是当前mine控制器,否则跳转新页面
        if targetViewController.userId == targetUser.userId {
            navigationController?.popToViewController(targetViewController, animated: true)
        } else { // 跳转到 新的mine控制器
            navigationController?.popToRootViewController(animated: false)
            let rootAppDelegate = UIApplication.shared.delegate as! AppDelegate
            let tabBarController = rootAppDelegate.window?.rootViewController as? BaseTabBarController
            let navController = tabBarController?.viewControllers?[0] as? UINavigationController
            navController?.pushViewController(MineViewController(), animated: true)
            tabBarController?.selectedIndex = 0
        }

你可能感兴趣的:(swift 不同tabbar 切换)