I have two views like this in Story Board:
[View1] -> [Navigation Controller] -> [View2]
To go from View1(has tableview) to View 2, i do this on click of a row on View1:
self.performSegueWithIdentifier("showmyview2", sender:self)
This works.
Now i have a button on View 2, which when clicked should take me back to previous view i.e View 1.
I tried this:
navigationController!.popViewControllerAnimated(true)
But this does not work. How do i go back to first view?
You can do it by selecting the View Controller in Storyboard editor and clicking Editor -> Embed In -> Navigation Controller. Also make sure that you have your Storyboard Entry Point (the arrow that indicates which view controller is presented first) either pointing to Navigation Controller or before it.
First Add a navigation controller to your First view1 through storyboard.(Editor->Embed Navigation controller), If navigation is not present.
OR
self.dismissViewControllerAnimated(true, completion: nil);
Call this function and try instead of navigation popviewcontroller
Use this code to present first view in your button action:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("FirstView") as! TableViewController
self.presentViewController(vc, animated: true, completion: nil)
And don't forget to give Id to your First view.
Select your firstView into storyBoard and then click on Identity Inspector and you can assign StoryBoard ID like show into below Image.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With