触摸UITableViewCell中的UIButton无法滚动表 [英] Touch on UIButton in a UITableViewCell cannot scroll the table

查看:131
本文介绍了触摸UITableViewCell中的UIButton无法滚动表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在UITableViewCell内放一个UIButton,一切正常,除了当我触摸按钮内部并移动手指时,表格不会滚动.

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.

我试图对UIButton进行子类化,并在touchesMoved:方法中将相同的消息发送给self.nextResponder,或调用touchesCancelled并希望它将touch事件传递给下一个响应者,但它们都不起作用.

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.

有什么好的方法可以解决这个问题?目前,我在UITableViewCell的顶部添加了UIView,并手动检测触摸事件,并将结果分别传递给按钮或单元格的其余部分,但这有点脏.

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.

推荐答案

您可以尝试将UITableView delaysContentTouches 属性设置为 YES .

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

您还可以将 canCancelContentTouches 设置为 YES .

Additionally you can set the canCancelContentTouches to YES.

如果此属性的值为NO,则滚动视图不滚动 内容视图开始跟踪后,无论手指是否移动.

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

来源: UIScrollView类参考

尝试:

_yourTableView.delaysContentTouches = YES;
_yourTableView.canCancelContentTouches = YES;

这篇关于触摸UITableViewCell中的UIButton无法滚动表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆