Swift 中的 If else 语句

If else Statement in Swift

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

该按钮工作正常,只需要再添加一条语句即可完成我的编码。

@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)

        }

    }

如果你指的是a:

您可以尝试以下方法:

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

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

请注意,所有 else if 语句都应放在最后的 else 语句之前