I am trying to pass a string from one if statement to another. I've declared the var outside of both if statements with just place holder strings for now.
What should be happening is that a button is tapped once and it displays the title of the button (think buttons/numbers on a calculator). When the button is tapped a second time it should display both the title of the first button press plus the title of the second button pressed in order to create a two-digit number.
What is actually happening is that it correctly displays button number one, but once the second button is hit it displays button number one as the place holder string.
The code is below. Any help would be great!
@IBAction func oneButtonPressed(sender: AnyObject)
{
timesButtonPressed += 1
var buttonTitle1:String! = ("Place ")
var buttonTitle2:String! = ("holder")
if timesButtonPressed == 1
{
buttonTitle1 = sender.titleLabel!?.text
self.answerTyped.text = String (buttonTitle1)
}
if timesButtonPressed == 2
{
buttonTitle2 = sender.titleLabel!?.text
self.answerTyped.text = String (stringInterpolation: buttonTitle1, buttonTitle2)
}
}
Aucun commentaire:
Enregistrer un commentaire