如果我返回Swift

时间:2017-08-01 08:42:40

标签: ios swift viewcontroller

我有ViewController1和ViewController2。当我单击ViewController1上的一个按钮时,应该转到ViewController2,当按下自定义后退按钮应该返回到ViewController1而不重新加载其内容为ex: - 如果我在ViewController1的文本字段上输入内容,它应保持原样。 有谁知道解决这个问题?

2 个答案:

答案 0 :(得分:2)

  

viewcontoller1按钮点击代码......

@IBAction func Parsent(sender: AnyObject) {
    let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "Identifier" as! ViewController2
    let navigationVC = UINavigationController(rootViewController: secondVC)
    self.present(navigationVC, animated: true, completion: nil)
 }
  

ViewController2按钮代码在这里..

@IBAction func Dismiss(sender: AnyObject) {
    self.dismissViewControllerAnimated(true, completion: nil)
 }

答案 1 :(得分:1)

1-加载View Controller 1

2-您的自定义按钮应该在视图控制器1的顶部显示ViewController 2(原生self.present执行此操作,请注意它将它显示在VC1之上,因此VC1仍然存在)

3- View Controller 2上的后退按钮取消了View Controller 2,您将返回View Controller 1,就像您离开时一样

希望这有帮助!