1

I'm running into a weird issue with trying to disable a like button after it's been pressed. It's just a standard UIButton in a UITableView, and I have a similar set up in other screens of my app, and it works fine on those views. Anyways, on this particular view, when say, the top button, is pressed, I have a line of code in my topButton(sender: UIButton) method that sets sender.enabled = false

When I watch the code execute in debug, the program hits this line and moves on like it worked fine, but the state of the button is never changed. It can be selected over and over again.

I also tried to set the state directly in the UITableViewCell class, and the result is the same. I changed the alpha value in that @IBAction and that part worked, but the button was still enabled.

I can't seem to figure out why it's doing this! Can anyone else offer some help?

EDIT: Posted code, although I thought I had included enough

@IBAction func topButton(sender: UIButton!) {
    sender.enabled = false
    let hitPoint = sender.convertPoint(CGPointZero, toView: self.tableView)
    let hitIndex = self.tableView.indexPathForRowAtPoint(hitPoint)
    let object = objectAtIndexPath(hitIndex)
    object.incrementKey("UpDown")
    object.saveInBackground()
}

Note that I tried topButton(sender: UIButton) and topButton(sender: UIButton!) and it didn't change anything.

Like I mentioned, everything else in the method executes fine, the activity is saved in the database, but the button is not disabled.

mugx
  • 9,869
  • 3
  • 43
  • 55
pbush25
  • 5,228
  • 2
  • 26
  • 35
  • Can you post your code? – Bigfoot11 Mar 10 '15 at 19:31
  • possible duplicate of [How do I disable a UIButton?](http://stackoverflow.com/questions/6210850/how-do-i-disable-a-uibutton) - use `userInteractionEnabled`. – Aaron Brager Mar 10 '15 at 19:39
  • Is your button getting reenabled somewhere else? Is the cell in which it lives getting recycled, for example? – i_am_jorf Mar 10 '15 at 19:40
  • Yes changing `userInteractionEnabled` to `false` does disable the button, but it does not change the image to it's disabled state like it does everywhere else in my app. Why the discrepancy? – pbush25 Mar 10 '15 at 19:42
  • @jeffamaphone yes it does, but I need to do that for cell reuse. I took it out of `cellForRowAtIndexPath:` and it does work, but in other `UITableViews` I do the same thing and the issue does not present itself. – pbush25 Mar 10 '15 at 19:47

0 Answers0