iDevelopper / PBRevealViewController

A UIViewController subclass for revealing a left and/or right view controller above or below a main view controller.
MIT License
80 stars 16 forks source link

Navigating to a navigationController from outside the menu #65

Closed Quailcreek closed 5 years ago

Quailcreek commented 5 years ago

Hi, I'm having some trouble and I could use a point in the right direction. I looked over all of the closed issues but I didn't see anything that I could use to make this work or if there was I didn't recognize it.

I had everything working just fine. Then I decided I wanted to have better control of the navBar on each VC so I embedded them in a navigationController. What I'm trying to do is navigate from the button to the navigationController as I have indicated with the green arrow.

This was the code that was working before I embedded the navigation controllers. The func is called from an alert action sheet generated from the button.

func figList() { let homeView = self.storyboard?.instantiateViewController(withIdentifier: "FigureList_VC") as! FigureList_VC self.navigationController?.pushViewController(homeView, animated: true) }

This code now throws the error that it cannot push a navigationController. I got it to work from the PBRevealViewController menu on the welcome VC with the code below. The thing is that I won't have the menu button active on the welcome VC on the final app version. I just made it active so I could trouble-shoot the problem.

if controllers[indexPath.row] == "FigureList_NavController" { if FigureList_NC == nil { FigureList_NC = storyboard.instantiateViewController(withIdentifier: controllers[indexPath.row]) as? UINavigationController } revealViewController()?.pushMainViewController(FigureList_NC!, animated:true) FigureList_NC = nil }

It doesn't throw any errors but it doesn't go to the navigationController either, it just sits there looking a me.

What am I doing wrong?

screen shot 2019-03-06 at 6 19 37 pm

iDevelopper commented 5 years ago

You have to push a view controller, not another navigation controller. If you really want to display another navigation controller, you need to present it, not push it. If you push the controller (FigureListVC), it will be added in the navigation controller stack.

revealViewController() is not a navigation controller (it is a container view controller) and pushMainViewController add a child view controller which in your cas is a navigation controller. After that, your navigation controller have to push an other controller, not a other navigation controller.

Quailcreek commented 5 years ago

Hi, Thank you for the education. I've only been on Xcode/Swift for a little over a month. I had it in my mind that if I imbedded the navigationController I had to navigate to the navigationController from then on. I didn't realize I could still just navigate to the to original viewController. I went back to my original code and it works fine. let homeView = self.storyboard?.instantiateViewController(withIdentifier: "FigureList_VC") as! FigureList_VC self.navigationController?.pushViewController(homeView, animated: true)