Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Touch on UIButton in a UITableViewCell cannot scroll the table

I need to have a UIButton inside a UITableViewCell, everything works fine except when I touch inside the button and move my finger, the table does not scroll.

I tried to subclass UIButton and in touchesMoved: method send the same message to self.nextResponder, or call touchesCancelled and hope it will pass the touch event to next responder, they both do not work.

Is there any good way to solve this problem? Currently I am adding a UIView on top of the UITableViewCell, and detecting touch events manually, passing result to the button or the rest of the cell respectively, but this is a little bit dirty.

like image 631
hzxu Avatar asked Dec 04 '11 22:12

hzxu


1 Answers

What you can try is setting the delaysContentTouches property of the UITableView to YES.

Additionally you can set the canCancelContentTouches to YES.

If the value of this property is NO, the scroll view does not scroll regardless of finger movement once the content view starts tracking.

Source: UIScrollView Class Reference

Try:

_yourTableView.delaysContentTouches = YES;
_yourTableView.canCancelContentTouches = YES;
like image 136
Rafa de King Avatar answered Oct 06 '22 21:10

Rafa de King