这是我用SWRevealViewController,UITabController,四个ViewControllers通过UINavgationController连接到UITabBarController的配置。选项卡条控制器设置为sw_front,左表视图设置为sw_rear。我用于sw_rear的代码是
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)
})
})
}
}
}代码正在正常工作并导航到视图控制器,但选项卡栏项没有显示。为了澄清,我附上了这些图片。有人能帮忙吗?我想在我的每个视图控制器中显示这个选项卡。
发布于 2018-03-10 19:07:28
您只应选择索引。
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)
}https://stackoverflow.com/questions/49212821
复制相似问题