Search code examples
swiftuiviewcontrolleruinavigationcontrolleruinavigationbar

child uiviewcontroller not loading on navigation bar


I was working on a side menu and transfering it to be over the navigation bar. But now I cannot seem to "load" the viewcontroller and all the click events go to the page under it.

It seems to me that the click events are stuck to the area of the navigation bar.

But the view controller does not run the viewDidLoad, I know this because the items of the menu are not created after Ive done this change.

The previous menu was like a view controller that slided over the current page.

This is the only code Ive changed / been working with

let navController = self.navigationController!
let mainV = navController.navigationBar
//let mainV = self.view --> OLD MENU CODE


mainV.addSubview(self.menuVC!.view)

//self.addChildViewController(self.menuVC!) --> OLD MENU CODE

navController.addChildViewController(self.menuVC!)
//navController.viewDidLoad()
//self.menuVC!.didMove(toParentViewController: navController)

//navController.isModalInPopover = true

//BaseViewController.menuVC?.didMove(toParentViewController: self)
self.menuVC!.view.layoutIfNeeded()

I did left my previous working code and attempts to fix the new code in comments

Any Ideas? thanks

-- UPDATE -- sudeently it seems the items are now being loaded


Solution

  • So I gave up on the idea of adding the view and controller to navigation bar. Instead I decided to create a modal view

                self.menuVC?.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext // allows transparency for the previous view
                self.present(self.menuVC!, animated: false, completion: nil)
                self.menuVC!.view.layoutIfNeeded()