Swift ios set a new root view controller

前端 未结 20 896
醉话见心
醉话见心 2020-12-13 04:46

I wonder if its possible to set a new root VC?

My app gets init with a uinavigation controller that has a table view to be the root VC.

Then from the table v

20条回答
  •  旧时难觅i
    2020-12-13 04:57

    In order to get the code snippet from the original question to work, I had to make a change to the third line

    let navigationController = self.navigationController!
    

    I am using this code in an @IBAction in the view controller that precedes the new root view controller.

    Using the original code, I was receiving an error saying that my view controller had no member called window. After looking at the documentation, I could find no property named window. I'm wondering if the original block of code above was intended to be used inside a UINavigationController file.

    Here is the block in its entirety.

    let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
    let todayViewController: TodaysFrequencyViewController = storyboard.instantiateViewControllerWithIdentifier("todaysFrequency") as! TodaysFrequencyViewController    
    let navigationController = self.navigationController!
    navigationController.setViewControllers([todayViewControl ler], animated: true)
    

提交回复
热议问题