iOS Swift 4 重启导航控制器
iOS Swift 4 Restart Navigation controller
我的故事板是这样的:
Navigation Controller -> StepOne -> StepTwo -> StepThree
StepOne
有 StepTwo
等的 Segue Show
在 StepOne
中,我打开 StepTwo
按钮,点击如下:
@IBAction func next(_ sender: UIButton) {
self.performSegue(withIdentifier: "oneToTwo", sender: self)
}
在StepTwo
中我用同样的方式打开StepThree
现在在我的最后一个 StepThree
我想在 StepOne
重新开始:
@IBAction func end_click(_ sender: UIButton) {
self.navigationController?.popToRootViewController(animated: false)
}
这很好用。
问题是所有 UI 元素仍然从第一个 运行 开始填充。当然,我可以在每个控制器中导航之前清除所有值,但这似乎不是一个好习惯。
有没有办法告诉 NavigationController
使用其 ViewController
的新实例?
我想你可以简单地关闭导航控制器的根视图控制器并重新呈现它。
你需要
// this inside end_click
let vc = self.storyboard!.instantiateViewController(withIdentifier:"StepOneId")
self.navigationController!.setViewControllers([vc], animated: true)
我的故事板是这样的:
Navigation Controller -> StepOne -> StepTwo -> StepThree
StepOne
有 StepTwo
等的 Segue Show
在 StepOne
中,我打开 StepTwo
按钮,点击如下:
@IBAction func next(_ sender: UIButton) {
self.performSegue(withIdentifier: "oneToTwo", sender: self)
}
在StepTwo
中我用同样的方式打开StepThree
现在在我的最后一个 StepThree
我想在 StepOne
重新开始:
@IBAction func end_click(_ sender: UIButton) {
self.navigationController?.popToRootViewController(animated: false)
}
这很好用。
问题是所有 UI 元素仍然从第一个 运行 开始填充。当然,我可以在每个控制器中导航之前清除所有值,但这似乎不是一个好习惯。
有没有办法告诉 NavigationController
使用其 ViewController
的新实例?
我想你可以简单地关闭导航控制器的根视图控制器并重新呈现它。
你需要
// this inside end_click
let vc = self.storyboard!.instantiateViewController(withIdentifier:"StepOneId")
self.navigationController!.setViewControllers([vc], animated: true)