代码之家  ›  专栏  ›  技术社区  ›  Bigfoot11

UIAlert故障

  •  0
  • Bigfoot11  · 技术社区  · 10 年前

    如果用户点击按钮并且标签文本为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 回复  |  直到 10 年前
        1
  •  2
  •   ztan    10 年前

    您正在比较 currentCountLabel UILabel设置为字符串零。你应该比较 当前计数标签 设置为字符串零。

    您可以更改

    if (currentCountLabel == "0")

    if (currentCountLabel.text == "0")