Ios Swift:如何在不添加segue的情况下切换回以前的UITableViewController

Ios Swift:如何在不添加segue的情况下切换回以前的UITableViewController,ios,swift,uitableview,segue,Ios,Swift,Uitableview,Segue,在我的iOS应用程序中,我希望在获得肯定结果后,屏幕切换回上一个屏幕。在我的情况下,我会从一个UITableViewController切换回另一个UITableViewController。我试过: self.dismissViewControllerAnimated(true, completion:nil) let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) let vc : UIT

在我的iOS应用程序中,我希望在获得肯定结果后,屏幕切换回上一个屏幕。在我的情况下,我会从一个UITableViewController切换回另一个UITableViewController。我试过:

self.dismissViewControllerAnimated(true, completion:nil)
let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let vc : UITableViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Tasks") as UITableViewController
self.presentViewController(vc, animated: true, completion: nil)
但它不起作用,什么也没有出现。 我也尝试过:

self.dismissViewControllerAnimated(true, completion:nil)
let mainStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let vc : UITableViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Tasks") as UITableViewController
self.presentViewController(vc, animated: true, completion: nil)
但是我在方法viewWillExample()中得到“致命错误:在展开可选值时意外发现nil”:


我可以避免从interface builder中添加另一个反向序列,然后执行performsguewithidentifier()。难道没有更快的方法吗?

您使用的是
UINavigationController
?如果是这样,只需调用
navigationController?.popViewControllerAnimated(true)
即可转到上一屏幕

如果未使用
UINavigationController
,则可以调用
dismissViewControllerAnimated(true,completion:nil)
,以获得相同的结果


在这两种情况下,您不需要像已经暗示的那样使用
self

好的,它与navigationController?完美配合。popViewControllerAnimated(true)但我被迫使用“self”:XCode要求我这样做,因为我在一个闭包中,处理来自NSURLSession.sharedSession()数据库的响应。dataTaskWithURL()啊,在这种情况下,是的,你需要自我。