Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mainViewController is nil #41

Closed
hadiidbouk opened this issue Dec 29, 2017 · 2 comments
Closed

mainViewController is nil #41

hadiidbouk opened this issue Dec 29, 2017 · 2 comments

Comments

@hadiidbouk
Copy link

Hello ,

I am showing the mainVC progmatically after performing some code in the appdelegate file,

The problem that i don't have any initial view controller in the storyboard.

the problem here self.contentView?.addSubview(self.mainViewController!.view)

the mainViewController is nil, i try to set it progmatically in my "MainVC" that extends PBRevealViewController but it seems that the loadView() in the PBRevealViewController start first.

@hadiidbouk
Copy link
Author

hadiidbouk commented Dec 29, 2017

I figure out that the problem is only happen when the segue is push not set.

@iDevelopper
Copy link
Owner

Hi, the code should be like this (if you don't want a right view controller, pass nil):

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        window = UIWindow(frame: UIScreen.main.bounds)
        
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        
        let mainViewController = storyboard.instantiateViewController(withIdentifier: "MainNavController")
        let leftNavController = storyboard.instantiateViewController(withIdentifier: "LeftNavController")
        let rightViewController = storyboard.instantiateViewController(withIdentifier: "RightViewController")
        
        let revealViewController = PBRevealViewController(leftViewController: leftNavController, mainViewController: mainViewController, rightViewController: rightViewController)
        
        window?.rootViewController = revealViewController
        
        window?.makeKeyAndVisible()
        
        return true
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants