代码之家  ›  专栏  ›  技术社区  ›  K. Mitra

带UITabBarController的SWRevealViewController

  •  0
  • K. Mitra  · 技术社区  · 6 年前

    app configuration

    这是我使用SWRevealViewController、UITabController和四个通过UINavgationController连接到UITabBarController的视图控制器进行的配置。选项卡栏控制器设置为sw\U front,左侧顶部表格视图设置为sw\U rear。我用于sw\U后部的代码是

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    
        let tabBarController = self.storyboard?.instantiateViewController(withIdentifier: "tabBar") as! MainTabBarController
    
        if(indexPath.row == 0){
            let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "superDeals") as! SuperDealsViewController
            let navigationController = UINavigationController(rootViewController: destinationVC)
            navigationController.setViewControllers([destinationVC], animated: true)
            tabBarController.setViewControllers([navigationController], animated: true)
            tabBarController.selectedIndex = 0
            self.revealViewController().setFront(tabBarController, animated: true)
            self.revealViewController().setFrontViewPosition(FrontViewPosition.left, animated: true)
        }else if(indexPath.row == 1){
            let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "allDeals") as! AllDealsViewController
            let navigationController = UINavigationController(rootViewController: destinationVC)
            navigationController.setViewControllers([destinationVC], animated: true)
            tabBarController.setViewControllers([navigationController], animated: true)
            tabBarController.selectedIndex = 1
            self.revealViewController().setFront(tabBarController, animated: true)
            self.revealViewController().setFrontViewPosition(FrontViewPosition.left, animated: true)
        }else if(indexPath.row == 2){
            let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "coupon") as! CouponsViewController
            let navigationController = UINavigationController(rootViewController: destinationVC)
            navigationController.setViewControllers([destinationVC], animated: true)
            tabBarController.setViewControllers([navigationController], animated: true)
            tabBarController.selectedIndex = 2
            self.revealViewController().setFront(tabBarController, animated: true)
            self.revealViewController().setFrontViewPosition(FrontViewPosition.left, animated: true)
        }else if(indexPath.row == 3){
            let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "forum") as! ForumViewController
            let navigationController = UINavigationController(rootViewController: destinationVC)
            navigationController.setViewControllers([destinationVC], animated: true)
            tabBarController.setViewControllers([navigationController], animated: true)
            tabBarController.selectedIndex = 3
            self.revealViewController().setFront(tabBarController, animated: true)
            self.revealViewController().setFrontViewPosition(FrontViewPosition.left, animated: true)
        }else if(indexPath.row == 4){
            let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "stores") as! StoresViewController
            let navigationController = UINavigationController(rootViewController: destinationVC)
            navigationController.setViewControllers([destinationVC], animated: true)
            self.revealViewController().setFront(navigationController, animated: true)
            self.revealViewController().setFrontViewPosition(FrontViewPosition.left, animated: true)
        }else if(indexPath.row == 5){
            let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "categories") as! categoriesViewController
            let navigationController = UINavigationController(rootViewController: destinationVC)
            navigationController.setViewControllers([destinationVC], animated: true)
            self.revealViewController().setFront(navigationController, animated: true)
            self.revealViewController().setFrontViewPosition(FrontViewPosition.left, animated: true)
        }else if(indexPath.row == 6){
            if(UserDefaults.standard.object(forKey: "token") == nil){
                let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "login") as! LoginViewController
                let navigationController = UINavigationController(rootViewController: destinationVC)
                navigationController.setViewControllers([destinationVC], animated: true)
                self.revealViewController().setFront(navigationController, animated: true)
                self.revealViewController().bounceBackOnLeftOverdraw = true
                self.revealViewController().setFrontViewPosition(FrontViewPosition.left, animated: true)
            }else{
                UserDefaults.standard.removeObject(forKey: "token")
                UserDefaults.standard.synchronize()
                let alert = UIAlertController(title: "Log out successful.", message: nil, preferredStyle: .alert)
                self.present(alert, animated: true, completion: nil)
    
                let when = DispatchTime.now() + 0.5
                DispatchQueue.main.asyncAfter(deadline: when, execute: {
                    alert.dismiss(animated: true, completion: {
                        let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "base") as! SWRevealViewController
                        self.present(vc, animated: true, completion: nil)
                    })
                })
            }
        }
    }
    

    代码正常工作并导航到viewcontrollers,但没有显示选项卡栏项。我已经附上了澄清的图像。有人能帮忙吗?我想在每个ViewController中显示选项卡栏。。

    How it should be

    How it is currently showing

    1 回复  |  直到 6 年前
        1
  •  0
  •   Shehata Gamal    6 年前

    您应该只选择索引

    let tabBarController = self.storyboard?.instantiateViewController(withIdentifier: "tabBar") as! MainTabBarController
    
    if(indexPath.row == 0){
    
        tabBarController.selectedIndex = 0
        self.revealViewController().setFront(tabBarController, animated: true)
        self.revealViewController().setFrontViewPosition(FrontViewPosition.left, animated: true)
    }