Search code examples
iosswiftuitableviewuinavigationcontrollerside-menu

How to set UINavigationController in SideMenu Controller using Xib (Not StoryBoards) to push new ViewController when Tableview Row Tapped in Swift 5


I am working with XIB files and make a sideMenu controller programatically using this Library https://github.com/Friend-LGA/LGSideMenuController. I make two function to propagate sideMenu in my project as here `//MARK Configure SideMenu

func moveToHomeController(){
    let viewController = self.configureSideMenu(viewController: HomeController())
    
    self.window?.rootViewController = viewController
    self.window?.makeKeyAndVisible()
}

func configureSideMenu(viewController: UIViewController)-> UIViewController {
    
    let contentController = SideMenuController(nibName: "SideMenuController", bundle: nil)
    let sidemnuNavigationController = UINavigationController(rootViewController:contentController)
    
    let navigationController = UINavigationController(rootViewController: viewController)
    
    let sideMenuController = LGSideMenuController(rootViewController: navigationController,
                                                  leftViewController: sidemnuNavigationController,
                                                  rightViewController: nil)
    
    sideMenuController.leftViewWidth = UIScreen.main.bounds.width - 100;
    sideMenuController.leftViewPresentationStyle = .slideAbove
    sideMenuController.leftViewAnimationDuration = 0.6
    sideMenuController.isLeftViewSwipeGestureEnabled = false
    sideMenuController.isRightViewSwipeGestureEnabled = false
    return sideMenuController
}

I get SideMenu working fine, now my problem is that whenever i click on tableview row(make in sideMenuController) to push to new viewcontroller it show half new viewcontroller above sidemenu same size as sideMenu. How i can get fullscreen viewcontroller with back button using pushViewController.Here is my code for row select

       `  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.row == 0{
        let viewController = EditProfileViewController(nibName:   "EditProfileViewController", bundle: nil)
        self.navigationController?.pushViewController(viewController, animated: true)
        self.sideMenuController?.hideLeftView()
        print("row tapped")
    }`

Solution

  • I checked and correct it as i was trying to present another viewcontroller screen over "LGSideMenuController" instead of using push transition.Solved using this piece of code.

     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        if indexPath.row == 0{
            let viewController =HomeController(nibName: "HomeController", bundle: nil)
                self.sideMenuController?.hideLeftViewAnimated(sender:self)
                self.sideMenuController?.rootViewController?.show(viewController, sender: self)
        }