简体   繁体   中英

Initial View Controller Not Appearing

I'm building a map app. The initial view controller says get started (GetStartedVC), which leads you to the next view controller so you can choose a place (PlaceVC), which then leads to a programmatic GoogleMap mapView (GoogleMapInterfaceVC). I have GetStartedVC set as my initial view controller upon launch. However, whenever I build and run the app, GoogleMapInterfaceVC is the initial view controller. I am concerned this problem is caused by my launch code in AppDelegate.swift ? Here is the code :

GMSPlacesClient.provideAPIKey("APIkey")
GMSServices.provideAPIKey("APIkey")

    self.window = UIWindow(frame: UIScreen.main.bounds)
    if let window = self.window {
        window.backgroundColor = UIColor.white
        window.accessibilityIdentifier = "GoogleMapInterfaceVC"

        let nav = UINavigationController()
        let mainView = GoogleMapInterfaceVC()
        nav.viewControllers = [mainView]
        window.rootViewController = nav
        window.makeKeyAndVisible()
    }

Is this the issue?

I know its been over a year. I'm surprised no one posted an answer. Did you ever solve this?

In the code snippet above you are placing a Navigation Controller as the root view controller and in the Nav Controller you are placing only the GoogleMapInterfaceVC. You should change this to the GetStartedVC like this.

let nav = UINavigationController()
    let mainView = GetStartedVC()
    nav.viewControllers = [mainView]
    window.rootViewController = nav
    window.makeKeyAndVisible()

Then, when the user does the appropriate action to choose a Place you do this

{
    navigationController.pushViewController(placeVC, animation: true)
}

and when the user selects the Map action

{
   navigationController.pushViewController(googleMapInterfaceVC, animation:true)
}

You should get the back button and pop view controller for free.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM