Swift以编程方式设置segues [英] Swift programmatically set segues

查看:90
本文介绍了Swift以编程方式设置segues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段解析代码,用于检查用户是否已登录:

I have a piece of parse code that checks to see if a user is logged in:

PFUser.logInWithUsernameInBackground("myname", password:"mypass") {
  (user: PFUser!, error: NSError!) -> Void in
  if user != nil {
    // Do stuff after successful login.
  } else {
    // The login failed. Check error to see why.
  }
}

成功登录后,我想将用户发送到新的服务器.我无法在情节提要中执行此操作,因为我只希望在满足条件的情况下进行segue.无论如何,可以通过编程来创建序列吗?

After the successful login I want to send the user to a new segue. I can't do this in the storyboard because I only want the segue to occur if the conditions are met. Is there anyway to create a segue programmatically?

推荐答案

您可以使用:

performSegueWithIdentifier("yourSegueIdentifier", sender: nil)

您不需要以编程方式创建" segue,只需连接ViewController并创建Segue.借助performSegueWithIdentifier,您可以根据需要手动调用segue.

You dont need to "create" a segue programmatically, just connect your ViewControllers and create a Segue. With performSegueWithIdentifier you can call your segue manually if needed.

这篇关于Swift以编程方式设置segues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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