0

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

  • I think you have a missunderstanding of `addChildVC` and should also look at navControllers and what they actually for. Have a look here: https://stackoverflow.com/a/18453401/1501847 – zero3nna Jul 20 '18 at 12:08
  • for some reason it started working as expected again – João Serra Jul 20 '18 at 12:19

1 Answers1

0

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()
  • hmm when i addChildView it does not overlay current navigationBar even I set frame = UIScreen.main.bounds, can you help? – famfamfam Jul 21 '20 at 05:08