1

I wanted to add sound and animation to button, but, it doesn't work, for example :

@IBAction func retry(sender: AnyObject) 
{
    buttonBeep?.play()
    sender.setImage(UIImage(named: "retryTwo.png")!, forState: .Highlighted)
    self.viewDidLoad()
}

My question is why it automatically jumps to viewDidLoad and does not comply first two line? and how can I fix it?

artG
  • 235
  • 3
  • 12

1 Answers1

0

Probably the first line doesn't get executed because buttonBeep is nil, so unwrapping the optional produces nil and the method is not called. For the second line, I think you firstly need to cast sender object, and then call setImage. You also have a typo at "sorState: .Highlighted", it is "forState"

What is the type of sender? Where is buttonBeep initialized?