应用不在标签

时间:2016-10-31 17:05:02

标签: ios swift string label

我正在尝试制作一个应用学生名称和总积分(等级为1000)的应用,并在按下按钮时将其显示在标签上。显示的公式是" x学生得到y等级。"出于某种原因(我不确定)我已连接故事板并且代码似乎正确;标签不显示字符串。相反,它给了我类似的东西:

" Optional(UITextField: 0x7ff6696095550; frame =" etc等。

如果有人可以查看我的代码并帮助我做我能做的事情,以便在标签上显示该字符串 - 我真的很感激。

    import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var gradeTF: UITextField!
    @IBOutlet weak var nameGR: UITextField!
    @IBOutlet var label1 : UILabel!


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }



    @IBAction func submitTapped(_ sender: UIButton) {

        var gradeMS = ""

        if (gradeTF.text?.isEmpty)! {

            gradeMS = "Please enter point total"

        }
        else {
            let grade : Int = Int(gradeTF.text!)!


            if grade > 1000 {
                gradeMS = "ERROR - Invalid point total"
                label1.text = gradeMS
            }
            else if grade > 900 && grade <= 1000 {
                gradeMS = "\(nameGR)'s grade is \"A\""
                label1.text = gradeMS
            }
            else if grade > 800 && grade <= 900 {
                gradeMS = "\(nameGR)'s grade is \"B\""
                label1.text = gradeMS
            }
            else if grade > 700 && grade <= 800 {
                gradeMS = "\(nameGR)'s grade is \"C\""
                label1.text = gradeMS
            }
            else if grade > 600 && grade <= 700 {
                gradeMS = "\(nameGR)'s grade is \"D\""
                label1.text = gradeMS
            }
            else {
                gradeMS = "\(nameGR)'s grade is \"F\""
                label1.text = gradeMS
            }
            }


        func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }


    }

}

2 个答案:

答案 0 :(得分:0)

您正在打印名为UITextField的{​​{1}}:

nameGR

但你可能想要打印它未打开的文字:

gradeMS = "\(nameGR)..."

完整方法:

guard let name = nameGR.text! else {
    print("Uups. We might want to handle empty textfield here")
}

gradeMS = "\(name)'s grade is \"C\""

答案 1 :(得分:0)

您应该使用1. Estimate parameters for X. 2. Transform parameters back into an image. 3. Do image processing to derive Y*. 4. Compute residuals using Y*. textField中的文本而不是textField本身。

<强>替换

nameGR

。通过

gradeMS = "\(nameGR)'s grade is \"A\""

gradeMS = "\(nameGR.text!)'s grade is \"A\"" 中的任何地方。

submitTapped IBAction