How to open TabBarController in ViewControllers, which launches from SlideMenuViewController

I want to have a tabBar in all of my ViewControllers. I implemented a SWRevealViewController that has two view controllers associated with it: TabBarController and the other a TableViewController. I want to have the same tabBar in all of my ViewControllers that Segues from TableViewController.

enter image description here

+7
ios objective-c swift uitabbarcontroller
source share
2 answers

I want to have a tabBar in all of my ViewControllers. I implemented the SWRevealViewController, which has two view controllers associated with one of them, the TabBarController, and the other, the TableViewController. I want to have the same tabBar in all of my ViewControllers, which is Segues from TableViewController.

You can do this, create a custom delegate and set the delegate from TableViewController and TabBarController to SWRevealViewController . Now for the first time let's say that you open the TableViewController , and when you click on any cell, you simply call the delegate method, which should be executed inside the SWRevealViewController class, and then execute segue inside this class, which should open the TabBarController and when you click the back button in the TabBarController , call the method again delegate , which must be executed inside the SWRevealViewController class and run segue to open the TableViewController

+2
source share

It should not be too complicated. Your RevealViewController (the source controller of your storyboard) already seems to be a subclass of SWRevealViewController . This is good, but it is not essential for this scenario. What you need is an implementation of the UIViewController for your side menu. The storyboard itself will not.

Also, I would not use segues here to switch between tabs, because segue has a destination view controller. Therefore, every time you execute segue, you create a new instance of the destination view controller. I would prefer to implement a UIViewController that handles the selection of a UITableView cell

Now suppose you create a UIViewController or UITableViewController as your menu (actually RearViewController ). Be sure to assign this class to your UITableViewController in the storyboard.

 class MenuViewController: UITableViewController { // MARK: UITableViewDelegate override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let tabIndex = indexPath.row let tabbarVC = (revealViewController().frontViewController as! UITabBarController) tabbarVC.selectedIndex = tabIndex // this assumes the menu items are in the same order as the tabs. if not you need to adjust this revealViewController().revealToggle(animated: true) // close the side menu after switching tabs } } 

that should be all you need

+1
source share

All Articles