Swift IF STATEMENT在Xcode中不起作用......出了什么问题?

时间:2015-03-05 05:26:49

标签: swift

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var labelSign: UILabel!

    @IBOutlet weak var nameEnter: UITextField!

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

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

    @IBAction func startButton(sender: AnyObject) {
        if nameEnter.text == "China" {
            labelSign.text == "A republic"
        } else {
            labelSign.text == "don't know"
        }
    }
}

我想要做的就是当我输入"中国"在文本字段中按"开始"信息标签将变为"共和国"。我的代码有问题吗?

1 个答案:

答案 0 :(得分:0)

labelsign.text中设置新文本时,必须使用赋值运算符=而不是等价运算符==。 现在,您只需检查labelSign.text是否等于"A republic"并保留该布尔值而不对其执行任何操作。