uzaylibeyb uzaylibeyb - 1 month ago 6
Swift Question

Play again button doesn't work

When I press the play again button it doesn't work. I just have this code involving the play again button. What should I add here? How can I add a function to

button? Here is my code:

let playAgain: UIButton = UIButton(frame: CGRectMake(-10, 400, 400, 150))
playAgain.setTitle("Play Again", forState: UIControlState.Normal)
playAgain.titleLabel!.font = UIFont(name: "Helvetica", size: 50)
playAgain.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside)
playAgain.tag = 1


Implement a function with any name you like, like this:

func buttonPressed(sender: UIButton) {
    // do something

Then set this function as the action of your button:

playAgain.addTarget(self, action: "buttonPressed:", forControlEvents: .TouchUpInside)