if语句中的performSegueWithIdentifier不起作用 [英] performSegueWithIdentifier in if statement isn't working

查看:249
本文介绍了if语句中的performSegueWithIdentifier不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用performSegueWithIdentifier为我的IBAction做了一个功能,它完全正常,直到现在它始终显示警报,但它也执行segue到下一个视图。我不知道我做错了什么。标识符在MainView中是wright。我无法找到任何答案来解决这个问题。

I have made a funtion for my IBAction with a performSegueWithIdentifier and it worked perfectly fine until now it always shows the alert but it also perform the segue to the next view. I don't know what I have done wrong. The identifier is wright in the MainView. I can't finde any answer to solve this.

@IBOutlet weak var backgroundImageView: UIImageView!
@IBOutlet weak var logInPassword: UITextField!
@IBAction func registerButton(sender: AnyObject) {
}

@IBAction func login(sender: AnyObject) {

    if logInPassword.text!.isEmpty {
        let alertNoPasswordLogIn = UIAlertView()
        alertNoPasswordLogIn.title = "Passwort fehlt"
        alertNoPasswordLogIn.message = "Bitte geben sie ein Passwort ein!"
        alertNoPasswordLogIn.addButtonWithTitle("Ok")
        alertNoPasswordLogIn.show()
    } else {
        self.performSegueWithIdentifier("Login", sender: self)
    }
}


推荐答案

我说你连了一个从您的登录按钮转到新场景将按钮的操作连接到您的登录(:)操作。这将导致操作被触发(并且在 if 语句的 true 分支之后)被解雇的segue。

I'd say you connected a segue from your login button to the new scene and connected the button's action to your login(:) action. This would result in the action being fired (and following the true branch of your if statement) and the segue being fired.

您可能要做的是从视图控制器拖动segue连接(而不是登录按钮,总是激活segue)到新场景。然后,这将导致仅触发操作,但也允许您在故事板中具有可以从代码中调用的命名segue。

What you probably meant to do was to drag the segue connection from the view controller (not the login button, which will always fire the segue) to the new scene. That will then result in firing ONLY the action but also allows you to have a named segue in your storyboard that you can call from your code.

仅从动作中拖动segue控制(如按钮),如果你总是希望它作为控件的动作执行(因为它总是会)。

Only drag segues from an action control (like a button) if you always want it to be performed as the control's action (because it always will be).

这篇关于if语句中的performSegueWithIdentifier不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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