Swift popToRoot not working

心已入冬 提交于 2019-12-31 00:30:06

问题


This highlighted line is where should popToRoot proceed, after a successful registration it should redirect to Root View Controller. For some reason it's not working for me, literally nothing happens, not even error.

I tried with

self.navigationController?.popToRootViewControllerAnimated(true)

回答1:


You don't appear to be using navigation controller at all, so I'd wager that self.navigationController is nil.

You could use an unwind segue. So in your root view controller, add a method like so:

@IBAction func unwindToRoot(segue: UIStoryboardSegue) {
    print("successfully unwound")
}

Then in your scoreboard scene from which you want to unwind, you can control-drag from the button to the "exit outlet":

When you let go, you can pick the unwind action:

This achieves the "pop to root" sort of functionality, but is not contingent upon using navigation controller.


If you want to perform this unwind programmatically, rather than doing the segue from the button to the exit outlet, do it from the view controller icon to the exit outlet:

Then, select the segue in the document outline and give this segue a unique storyboard id:

Then you can programmatically perform the segue, using the same identifier string:

performSegueWithIdentifier("UnwindToRoot", sender: self)


来源:https://stackoverflow.com/questions/29176131/swift-poptoroot-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!