Reputation: 681
I have ViewController1 and ViewController2 . When i click a button on the ViewController1 should go to ViewController2 and when press a custom back button should return to ViewController1 without reloading its content for ex:- if i type something on ViewController1's text filed it should remain as it is. Does anyone knows any solution for this?
Upvotes: 1
Views: 859
Reputation: 1429
viewcontoller1 button click code...
@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 button code here..
@IBAction func Dismiss(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
Upvotes: 2
Reputation: 2099
1- Load View Controller 1
2- Your custom button should present ViewController 2 on top of view controller 1 (the native self.present does this, note that it present it on top of VC1 so VC1 is still there)
3- your back button on View Controller 2 dismisses View Controller 2 and you return to View Controller 1 the same as you left it
Hope this helps!
Upvotes: 1