Programmatically go back to previous ViewController in Swift

前端 未结 15 1563
野的像风
野的像风 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:47

    Swift 4.0 Xcode 10.0 with a TabViewController as last view

    If your last ViewController is embebed in a TabViewController the below code will send you to the root...

    navigationController?.popToRootViewController(animated: true)
    navigationController?.popViewController(animated: true)
    

    But If you really want to go back to the last view (That could be Tab1, Tab2 or Tab3 view..)you have to write the below code:

    _ = self.navigationController?.popViewController(animated: true)
    

    This works for me, i was using a view after one of my TabView :)

提交回复
热议问题