Programmatically go back to previous ViewController in Swift

前端 未结 15 1527
野的像风
野的像风 2020-12-04 04:50

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 ba

15条回答
  •  一整个雨季
    2020-12-04 05:54

    Swift 4

    there's two ways to return/back to the previous ViewController :

    1. First case : if you used : self.navigationController?.pushViewController(yourViewController, animated: true) in this case you need to use self.navigationController?.popViewController(animated: true)
    2. Second case : if you used : self.present(yourViewController, animated: true, completion: nil) in this case you need to use self.dismiss(animated: true, completion: nil)

    In the first case , be sure that you embedded your ViewController to a navigationController in your storyboard

提交回复
热议问题