因此,我是编码的新手,只要您单击同一按钮,我就希望使标签更改其文本。这样做是尽管您可以将变量绑定到内部,但如果使用if语句,则隐藏起来不起作用。这是代码:
@IBAction func buttonOne(_ sender: Any)
{
var nextText:Int = 1
nextText += 1
if nextText == 2
{
labelOne.text = "We have a developing situation."
}
if nextText == 3
{
labelOne.text = "About forty five minutes ago 15 unknown assailant broke into Chicago 1st State Bank"
}
if nextText == 4
{
labelOne.text = "They are armed and dangerous and have taken numerous hostages"
}
if nextText == 5
{
labelOne.text = "Your mission is to take you and your partner in to bank and free the hostages"
}
if nextText == 5
{
labelOne.text = "You shall enter the bank via helicopter and rappel onto the roof, good luck."
}
}
在按钮点击功能范围之外声明nextText
var nextText:Int = 1
@IBAction func buttonOne(_ sender: Any)
{
nextText += 1
switch nextText{
case 2 : labelOne.text = "We have a developing situation."
case 3 : labelOne.text = "About forty five minutes ago 15 unknown assailant broke into Chicago 1st State Bank"
case 4 : labelOne.text = "They are armed and dangerous and have taken numerous hostages"
case 5 : labelOne.text = "Your mission is to take you and your partner in to bank and free the hostages"
case 6 : labelOne.text = "You shall enter the bank via helicopter and rappel onto the roof, good luck."
default : labelOne.text = ""
}
}