0

I have a weird bug where a buttons touchUpInside does not work as it should. I have two buttons using the same code

@IBOutlet weak var previousIBO: UIButton!
@IBOutlet weak var nextIBO: UIButton!

@IBAction func buttonDown(sender: AnyObject) {
    nextSingleFire()
    timer = Timer.scheduledTimer(timeInterval: 0.2, target: self, selector:#selector(nextFire), userInfo: nil, repeats: true)
}
@IBAction func buttonUp(sender: AnyObject) {
    timer.invalidate()
}

nextIBO.addTarget(self, action:#selector(buttonDown(sender:)), for: .touchDown)
    nextIBO.addTarget(self, action:#selector(buttonUp(sender:)), for: [.touchUpInside, .touchUpOutside, .touchDragOutside])
    previousIBO.addTarget(self, action:#selector(buttonDown(sender:)), for: .touchDown)
    previousIBO.addTarget(self, action:#selector(buttonUp(sender:)), for: [.touchUpInside, .touchUpOutside])

However the previous button only works when I drag after tapping. as opposed to the next button that works simply by tapping. Why am I getting this weird behavior in this one button?

I would like to add.touchDragOutside to my previous button, but I can't because then the button does not work

baxu
  • 303
  • 1
  • 4
  • 12

1 Answers1

0

If I were you, I'd start by removing the @IBAction on your functions.
As far as I can tell, they are useless, since you set the actions via "addTarget". And there's a chance your weird behaviour is caused by a wrong connection between your buttons and functions (select your buttons, and open the "Connections inspector" to check if everything is fine).

One other possibility is that your buttons are overlapping, or some view is blocking your button.

Also, Timers can be tricky, take a look at this post for starting and stoping them: swift invalidate timer doesn't work

Community
  • 1
  • 1
Xavier Daleau
  • 501
  • 5
  • 6