4

I have a UITableView with dynamically populated rows, but also there's a section at the top that contains one special cell (with a different identifier) which is always the same.

I've added two buttons to this cell and they do work, however they react poorly. That is, the highlighting occurs only after about 0.25s.

I'm using the following slightly customized button:

import UIKit

class HighlightingButton: UIButton {

    override var isHighlighted: Bool {
        didSet {
            if isHighlighted {
                backgroundColor = UIColor.lightGray
            } else {
                backgroundColor = UIColor.white
            }
        }
    }

}

It's important that the user gets a clear feedback that they tapped the button. However with the slow highlighting this isn't satisfying, although the events seem to be triggered quickly (juding by printing some output).

In a normal view this HighlightingButton works as expected and the highlighting flashes as quickly as I can tap.

Is there something in the event handling of the UITableViewCell that leads to this slowness?

Update

I created a minimalistic example project that demonstrates the problem. There aren't any GestureRecognizers and still there's this very noticable delay.

Frederick Squid
  • 591
  • 4
  • 16
  • The issue is probably not about the button and not about UITableViewCell class. I've tried your button on a cell and there are no issues with it. Perhaps you have a long press gesture on that cell or anything else, which we should be aware of? – alexburtnik Oct 21 '16 at 19:38
  • I created a minimalistic example project that demonstrates the problem. So it also happens in a very plain setting without any surrounding interferences. If you get around to having a look, I'd appreciate it. – Frederick Squid Oct 22 '16 at 16:37

1 Answers1

5

Take a look at delaysContentTouches property of UIScrollView. I fixed your problem by setting it to false on tableView and all of it's scrollview subviews.

So you should just add a tableView IBOutlet and override viewDidLoad method like this:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delaysContentTouches = false
    for case let subview as UIScrollView in tableView.subviews {
        subview.delaysContentTouches = false
    }
}
alexburtnik
  • 7,661
  • 4
  • 32
  • 70