如何使用Swift在Xcode 6中执行自动segue? [英] How do I perform an auto-segue in Xcode 6 using Swift?

查看:126
本文介绍了如何使用Swift在Xcode 6中执行自动segue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在应用加载后的一段时间后,从主viewController自动切换到第二个视图控制器。

I wish to auto-segue from the main viewController to a second view controller after a set period of time after an app loads.

我该怎么做?

我是否需要以编程方式进行?

Do I need to do it programmatically?

推荐答案

如果你的UI在Storyboard中布局,您可以在第一个 viewDidLoad 中设置 NSTimer ViewController 然后在计时器触发时调用 performSegueWIthIdentifier

If your UI is laid out in a Storyboard, you can set an NSTimer in viewDidLoad of your first ViewController and then call performSegueWIthIdentifier when the timer fires:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let timer = Timer.scheduledTimer(interval: 8.0, target: self, selector: #selector(timeToMoveOn), userInfo: nil, repeats: false)
    }

    @objc func timeToMoveOn() {
        self.performSegue(withIdentifier: "goToMainUI", sender: self)
    }






以下是在故事板中设置segue的方法:


Here is how you set up the segue in the Storyboard:


  1. 控制从第一个 ViewController 的文件所有者图标拖动到第二个 ViewController

  2. 从弹出窗口中选择模态。

  1. Control drag from the File's Owner icon of the first ViewController to the second ViewController.
  2. Choose "modal" from the pop-up.


  1. 单击视图控制器之间出现的 segue箭头。在segue的属性检查器中...

  2. 为您的segue提供标识符。

  3. 关闭动画如果您不想看到屏幕滑入。

  1. Click on the segue arrow that appears between the view controllers. In the Attributes Inspector for the segue...
  2. Give your segue an Identifier.
  3. Turn off Animates if you don't want to see the screen slide in.

这篇关于如何使用Swift在Xcode 6中执行自动segue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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