SWRevealViewController 与 UITabBarController
SWRevealViewController with UITabBarController
app configuration
这是我的配置,包含 SWRevealViewController、UITabController、四个通过 UINavgationController 连接到 UITabBarController 的 ViewController。标签栏控制器设置为 sw_front,左上角 table 视图设置为 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)
})
})
}
}
}
代码正常运行并正确导航到视图控制器,但标签栏项目未显示。我附上了图片以供澄清。有人可以帮忙吗?我想在我的每个视图控制器中显示标签栏..
How it should be
How it is currently showing
你应该只select索引
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)
}
app configuration
这是我的配置,包含 SWRevealViewController、UITabController、四个通过 UINavgationController 连接到 UITabBarController 的 ViewController。标签栏控制器设置为 sw_front,左上角 table 视图设置为 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)
})
})
}
}
}
代码正常运行并正确导航到视图控制器,但标签栏项目未显示。我附上了图片以供澄清。有人可以帮忙吗?我想在我的每个视图控制器中显示标签栏..
How it should be
How it is currently showing
你应该只select索引
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)
}