Jasper Jasper -4 years ago 249
iOS Question

iOS: Go back to previous view

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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download