以编程方式调用segue无法正常工作 [英] Calling segue programmatically not working

查看:64
本文介绍了以编程方式调用segue无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作启动画面.我有一个视图,上面绘制了背景图像,然后几秒钟后我想过渡到另一个视图.我正在尝试使用以下代码:

I am trying to make a splash screen. I have a view that has a background image being drawn onto it and then another view I want to transition to after a few seconds. I am trying to use the following code:

self.performSegueWithIdentifier("showApp", sender: self)

我通过ctrl +拖动一条线从另一条线到另一条线在两个视图之间创建了一个序列.我将segue的标识符设置为"showApp".

I created a segue between the two views by ctrl+dragging a line from one to the other. I set the segue's identifier to "showApp".

当我运行代码时,什么也没有发生,也没有错误.有什么想法吗?

When I run the code nothing happens and there are no errors. Any ideas?

以下是启动屏幕的控制器:

Here is the controller for the splash screen:

class SplashViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        sleep(2)

        // THIS DOES NOTHING:
        self.performSegueWithIdentifier("showApp", sender: self)

        // THIS AS SUGGESTED ALSO DOES NOTHING:
        var otherViewController:UIViewController = self.storyboard.instantiateViewControllerWithIdentifier("test") as UIViewController
        self.presentViewController(otherViewController, animated: true, completion: nil)
    }
}

推荐答案

通常,您需要导航控制器才能使用segue.

Normally, you need a navigation controller in order to use segue.

突出显示情节提要中的SplashViewController对象,然后转到

Highlight your SplashViewController object inside the Storyboard and go to

编辑器->嵌入->导航控制器

在那之后,删除Clement建议的代码并尝试再次运行该项目,您应该获得预期的结果.

After that, remove the code suggested by Clement and try running the project again, you should get the result that you expected.

这篇关于以编程方式调用segue无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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