Question

I have a subclass of UIButton placed inside a UITableViewCell's contentView. The problem I am having is that when I press the button and scroll the table (quickly) the button's setHighlighted: method gets called three times, all with YES as the parameter. The button never gets de-highlighted when the table scrolls (so when I finish the scroll one of my buttons looks like it's depressed, but there are no longer any fingers on the screen). If I press the button, wait a second, and then scroll the table does not scroll and the button gets de-highlighted properly (when the touch event exits the button's frame).

I have tried setting the tableView to

self.tableView.canCancelContentTouches = NO;
self.tableView.delaysContentTouches = NO;

But that doesn't help (and setting delaysContentTouches = NO actually makes the table non-scrollable). I haven't tried setting these in the new UITableViewCellScrollView because that is private and I didn't want to add new code for if IOS7, else...

The setHighlighted: calls come from UIControl touchesBegan:, UIControl touchesMoved, and UIControl touchesEnded:. I never get anything from UIControl touchesCancelled: which is what I would expect when the tableView takes over control of the touch events for scrolling.

I can add code if anyone thinks I am doing something wrong, but this seems like more of a concept question to me.

Why am I not getting setHighlighted:NO from UIControl touchesCancelled:?

I have not tried using a non-subclassed UIButton and setImage:forState: yet because my highlighted states are just gradient changes and I didn't want to create a UIImage for them. but I can if I have to.

Was it helpful?

Solution

This may not be the correct way to process this, but since no one else has offered any other solutions I did just find a way to resolve the issue I was having. Since the default touchesCancelled apparently doesn't send a setHighlight:NO message to my button sublcass, I overloaded the touchesCancelled function in my UIButton subclass and called [self setHighlighted:NO]. That seems to resolve the issue where the buttons stay highlighted when the table scrolls.

Just in case anyone else comes upon this problem in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top