Swift popToRoot 不起作用 [英] Swift popToRoot not working

查看:56
本文介绍了Swift popToRoot 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个突出显示的行是 popToRoot 应该继续的地方,在成功注册后,它应该重定向到根视图控制器.出于某种原因,它对我不起作用,实际上什么也没发生,甚至没有错误.

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.

我试过

self.navigationController?.popToRootViewControllerAnimated(true)

推荐答案

你似乎根本没有使用导航控制器,所以我打赌 self.navigationController.

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

您可以使用 unwind segue.所以在你的根视图控制器中,添加一个像这样的方法:

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")
}

然后在您想要放松的记分牌场景中,您可以control-从按钮拖动到退出出口":

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:

这实现了pop to root"功能,但不依赖于使用导航控制器.

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:

然后,在文档大纲中选择 segue 并给这个 segue 一个唯一的故事板 ID:

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)

这篇关于Swift popToRoot 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆