0
votes

I've implemented side bar using SWRevealViewController. But when i do same using Tab bar based view controller, menu icon is invisible only in tab based screens. Icon is visible in interface builder but invisible in simulator/device. Functionality is working in every screen, even in tab based view controller. When i drag from left to right and vice versa, functionality is working fine. Only the issue is menu icon is invisible in simulator. Can anyone help me?

Thanks in advance.

below is the swift file for tab

import UIKit

class ItemOneViewController: UIViewController {


@IBOutlet weak var menuBar: UIBarButtonItem!
override func viewDidLoad() {
    super.viewDidLoad()

    setMenuBarBtn(menuBar: menuBar)

    navigationController!.navigationBar.barTintColor = UIColor.color(.blue)
}

func setMenuBarBtn(menuBar: UIBarButtonItem) {
    menuBar.target = revealViewController()
    menuBar.action = #selector(SWRevealViewController.revealToggle(_:))
    view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}

func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.portrait
}
} 

Code is similar for three tabs.

I've done below tasks before asking question here

  1. Deleted and recreated screens two times.
  2. Cross checked everything and compared tab bar based scenes source code with other scenes.
  3. googled it.

Below are the images for your reference

Tab based screen with side bar functionality (working good)

Tab based screen without menu icon (Problem persist here , i want menu icon to be displayed)

HomeScreen with menu icon (Working good)

Navigation Controller attribute inspector

my storyboard

Item One View Controller view hierarchy

Item One view Controller related navigation controller scene

2
try adding these lines in viewDidlayoutSubViews setMenuBarBtn(menuBar: menuBar) navigationController!.navigationBar.barTintColor = UIColor.color(.blue)Abu Ul Hassan
No, it is not working @AbuUlHassanEswar
if you hide tabbar button appears or not ?Abu Ul Hassan
i didn't hide anything , it is button item and i can see it in interface builder, invisible in simulator/real deviceEswar
i got your issue... give me a minuteAbu Ul Hassan

2 Answers

0
votes

You gave to add normal button on HomeViewController enter image description here

Then directly perform segue through storyboard(from burger menu button).

@IBAction func sideMenuBtnAction(_ sender: UIButton) {
         performSegue(withIdentifier: "sideMenu", sender: self)
    }

enter image description here Then on SideMenuController :

import UIKit
import SideMenu

class SideMenuViewController: UIViewController {


    @IBOutlet var sideMenuTableView: UITableView!

    override func viewDidLoad() {
            super.viewDidLoad()

            SideMenuManager.default.menuPresentMode = .menuSlideIn
            SideMenuManager.default.menuFadeStatusBar = false
            SideMenuManager.default.menuWidth = self.view.frame.width / 1.4
            SideMenuManager.default.menuShadowOpacity = 0.3
            sideMenuTableView.tableFooterView = UIView(frame: .zero)
      }
 }
0
votes

You need to create a tabbarController class like below, and assign this ViewController class to tabbar on storyboard ... I have not tested this code but something like this should work for your case

class ViewController: UITabBarController {

override func viewDidLoad() {
    super.viewDidLoad()
    let firstSw = setRootViewControllerFor(identifier: "firstViewController") as! SWRevealViewController
    let secondsw = setRootViewControllerFor(identifier: "secondViewController") as! SWRevealViewController
    let thirdSw = setRootViewControllerFor(identifier: "thirdController") as! SWRevealViewController
    self.viewControllers = [firstSw,secondsw, thirdSw]
    // Do any additional setup after loading the view.
}

func setRootViewControllerFor(identifier:String)->SWRevealViewController
{
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let sw = storyboard.instantiateViewController(withIdentifier: "sw") as! SWRevealViewController
    self.view.window?.rootViewController = sw
    let destinationController = self.storyboard?.instantiateViewController(withIdentifier: identifier)
    let navigationController = UINavigationController(rootViewController: destinationController!)
    navigationController.navigationBar.isHidden=false
    navigationController.setNavigationTints()        //call your UI method to set 
    sw.setFront(navigationController, animated: true)
    return sw
}

/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destination.
    // Pass the selected object to the new view controller.
}
*/

}

OR Following by doing this there is no need to create a tabbarController

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // create UIWindow with the same size as main screen
    window = UIWindow(frame: UIScreen.mainScreen().bounds)

    // create story board. Default story board will be named as Main.storyboard in your project.
    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    // create view controllers from storyboard
    // Make sure you set Storyboard ID for both the viewcontrollers in 
    // Interface Builder -> Identitiy Inspector -> Storyboard ID
    let firstSw = setRootViewControllerFor(identifier: "firstViewController") as! SWRevealViewController
    let secondsw = setRootViewControllerFor(identifier: "secondViewController") as! SWRevealViewController
    let thirdSw = setRootViewControllerFor(identifier: "thirdController") as! SWRevealViewController

    // Set up the Tab Bar Controller to have two tabs
    let tabBarController = UITabBarController()
    tabBarController.viewControllers =  [firstSw,secondsw, thirdSw]

    // Make the Tab Bar Controller the root view controller
    window?.rootViewController = tabBarController
    window?.makeKeyAndVisible()

    return true
}


 func setRootViewControllerFor(identifier:String)->SWRevealViewController
    {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let sw = storyboard.instantiateViewController(withIdentifier: "sw") as! SWRevealViewController
        self.view.window?.rootViewController = sw
        let destinationController = self.storyboard?.instantiateViewController(withIdentifier: identifier)
        let navigationController = UINavigationController(rootViewController: destinationController!)
        navigationController.navigationBar.isHidden=false
        navigationController.setNavigationTints()        //call your UI method to set 
        sw.setFront(navigationController, animated: true)
        return sw
    }