Christian Christian - 4 months ago 53
Swift Question

Programmatically go back to previous ViewController in Swift

I send the user over to a page on a button click. This page is a UITableViewController.

Now if the user taps on a cell, I would like to push him back to the previous page.

I thought about something like

self.performSegue("back")....
but this seems to be a bad idea.

What is the correct way to do it?

Answer

If you want to go back to the previous view controller

navigationController?.popViewControllerAnimated(true)

If you want to go back to the root view controller

navigationController?.popToRootViewControllerAnimated(true)