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

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

问题描述

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

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 以编程方式设置转场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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