Swift 中的条件转场 [英] Conditional Segue in Swift

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

问题描述

我想在我的应用中创建一个连接"按钮.当您点击它时,如果您登录正确,它将打开一个新页面.

I want to do a "connexion" button in my app. And when you tap on it, it will open a new page if you have correct login.

但是,我读到我们无法撤消转场,我想我需要手动调用它.你有什么想法吗?

But, I read that we can't undo a segue, I suppose I need to call it manually. Do you have an idea ?

我仍然尝试过这样的事情:

I still tried something like this :

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject) {
    if checkLog == true
    {
     //finish   
    }
    else
   {
    // undo
   }
}

@IBAction func ConexTAP(sender: UIButton)
{
 //check login
}

推荐答案

您可以在 ViewController 中使用以下方法进行凭据检查:

You can do the credentials check in the following method in your ViewController:

func shouldPerformSegueWithIdentifier(_ identifier: String!,
                              sender: AnyObject!) -> Bool

或者,您可以将 UIButton 绑定到视图控制器中的操作,在此处执行检查,然后通过代码触发 segue.

In alternative, you can bind the UIButton to an action in your view controller, perform the checks here and then trigger a segue by code.

这篇关于Swift 中的条件转场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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