My storyboard looks like this:

Navigation Controller -> StepOne -> StepTwo -> StepThree

StepOne has a Segue Show to StepTwo etc.

In StepOne I open StepTwo on Button click like this:

 @IBAction func next(_ sender: UIButton) {

     self.performSegue(withIdentifier: "oneToTwo", sender: self)

 }

In StepTwo I open StepThree the same way.

Now In my last StepThree I want to restart at StepOne :

@IBAction func end_click(_ sender: UIButton) {
    self.navigationController?.popToRootViewController(animated: false)
}

This works fine.

The problem is that all the UI elements are still filled out from the first run. Of course I could clear all values before I navigate in each controller but this doesn't seem to be good practice.

Is there a way to tell NavigationController to use new instances of its ViewController s ?

2 Answers

1
Sh_Khan On Best Solutions

You need

// this inside end_click
let vc = self.storyboard!.instantiateViewController(withIdentifier:"StepOneId")
self.navigationController!.setViewControllers([vc], animated: true)
2
Mihir On

I guess you can simply dismiss the root view controller of navigation controller and present it again.