首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SWRevealViewController与UITabBarController

SWRevealViewController与UITabBarController
EN

Stack Overflow用户
提问于 2018-03-10 18:53:08
回答 1查看 138关注 0票数 0

app配置

这是我用SWRevealViewController,UITabController,四个ViewControllers通过UINavgationController连接到UITabBarController的配置。选项卡条控制器设置为sw_front,左表视图设置为sw_rear。我用于sw_rear的代码是

代码语言:javascript
复制
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)
                })
            })
        }
    }
}

代码正在正常工作并导航到视图控制器,但选项卡栏项没有显示。为了澄清,我附上了这些图片。有人能帮忙吗?我想在我的每个视图控制器中显示这个选项卡。

应该是什么样子

它目前是如何显示

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-10 19:07:28

您只应选择索引。

代码语言:javascript
复制
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)
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49212821

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档