xcode Swift 中的 If else 语句

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28331082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:36:09  来源:igfitidea点击:

If else Statement in Swift

xcodeswiftif-statement

提问by Coder

I'm a newbie at swift, so how do I add an extra else if statement saying greater than 56 & less than 65 to my button?

我是 swift 的新手,那么我如何向我的按钮添加一个额外的 else if 语句,表示大于 56 且小于 65?

The button work fine, it just need one more additional statement added to finished up my coding.

该按钮工作正常,它只需要添加一个额外的语句来完成我的编码。

@IBAction func Submit4Button(sender: AnyObject) {

        let a: Float? = (EnterH4Dimension.text as NSString).floatValue

        if a > 65 {

            self.DimensionLabel.text = " Cameron H4 With Guide Pins."

            yesButton.hidden = false
            noButton.hidden = false

            emailButton.hidden = true
            DimensionLabel.hidden = false

            self.view.endEditing(true)

        }

        else if EnterH4Dimension.text == "" {

            noButton.hidden =  true
            yesButton.hidden = true

            var alert = UIAlertController(title: "Dimension", message: "Missing Data Input.", preferredStyle: UIAlertControllerStyle.Alert)

            alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))

            self.presentViewController(alert, animated: true, completion: nil)

        }

        else {

            self.DimensionLabel.text = "Dimensions meet guideline"

            noButton.hidden =  true
            yesButton.hidden = true

            DimensionLabel.hidden = false
            shallowDimButton.hidden = true
            emailButton.hidden = false
            self.view.endEditing(true)

        }

    }

回答by Jér?me

If you are referring to a:

如果您指的是a

You can try the following:

您可以尝试以下操作:

else if a > 56 && a < 65  {}

Depending on whether or not you want to include 56 and 65 you can use <=& >=

根据您是否要包括 56 和 65,您可以使用<=&>=

Note that all your else ifstatements should be place before the final elsestatement

请注意,您的所有else if陈述都应放在最终else陈述之前