UIAlert麻烦

时间:2015-02-23 21:07:04

标签: swift if-statement uibutton uialertview

如果用户点击按钮并且标签文本为0,我试图显示UIAlert。我希望按钮在单击按钮后将标签文本更改为0。当我试图这样做时,UIAlert出现在我不想要的时候。这是我的按钮代码:

@IBAction func checkButton(sender: UIButton) {

    if (currentCountLabel == "0"){

        let alert = UIAlertView()
        alert.title = "Alert"
        alert.message = "You must type in an answer in order to check it"
        alert.addButtonWithTitle("Understood")
        alert.show()

    }

    currentCount *= 0
    currentCountLabel.text = "\(currentCount)"

}

如何让按钮将标签的文本更改为0,但更改文本时错误没有消失?

先谢谢。

1 个答案:

答案 0 :(得分:2)

您正在将currentCountLabel UILabel与字符串零进行比较。您应该将currentCountLabel的文本与字符串零进行比较。

您可以更改

if (currentCountLabel == "0")

if (currentCountLabel.text == "0")