惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
博客园_首页
WordPress大学
WordPress大学
博客园 - 聂微东
P
Privacy International News Feed
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Last Week in AI
Last Week in AI
C
CERT Recently Published Vulnerability Notes
月光博客
月光博客
NISL@THU
NISL@THU
美团技术团队
T
Tailwind CSS Blog
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
C
Cisco Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Hacker News
The Hacker News
B
Blog
P
Palo Alto Networks Blog
L
Lohrmann on Cybersecurity
有赞技术团队
有赞技术团队
The Register - Security
The Register - Security
S
Securelist
A
Arctic Wolf
MyScale Blog
MyScale Blog
H
Help Net Security
N
Netflix TechBlog - Medium
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
Threatpost
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Security Latest
Security Latest
T
Tor Project blog
V
Vulnerabilities – Threatpost
V
V2EX
AI
AI
Hugging Face - Blog
Hugging Face - Blog
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
Simon Willison's Weblog
Simon Willison's Weblog
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Troy Hunt's Blog
Schneier on Security
Schneier on Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Heimdal Security Blog
Google Online Security Blog
Google Online Security Blog
Know Your Adversary
Know Your Adversary

博客园 - zhoup

文鹏教育_jmeter培训_逻辑控制器_循环取样器 02 jmeter性能测试系列_JForum测试论坛的环境搭建 01 jmeter性能测试系列_Jmeter的体系结构 NSTimer的使用[zhuang] 实战p12文件转pem文件 UIViewContentMode各类型效果 给iOS开发新手送点福利,简述文本属性Attributes的用法 IOS 设置导航栏全局样式 xcode 插件地址 AFNnetworking详解 NSRunLoop详解 利用SQL注入漏洞登录后台的实现方法 Xcode 7免证书真机调试 [转]CABasicAnimation用法 zhuang 定制iOS 7中的导航栏和状态栏 zhuang 自定义Xcode代码模板:Code Snippet [zhang] ViewController的生命周期分析和使用 iOS开发--一些UITabBarItem属性的设置[转] UINavigationItem UINavigationBar 关系分析[转]
iOS 在tableView上添加button导致按钮没有点击效果和不能滑动的 zhuang
zhoup · 2016-01-06 · via 博客园 - zhoup

转载请注明出处。

今天在调试代码的时候,在tableviewcell上添加button,发现button快速点击的话,是看不出点击效果的,查找资料发现,

 ios7上UITableViewCell子层容器是UITableViewCellScrollView,

ios6的则是UITableViewCellContentView.点击效果应该是被ScrollView的触摸延迟给阻拦了。

经过一番摸索,终于找到解决方法。

第一步:将 tableView  的 delaysContentTouches 设置为NO,

第二步:在自定义cell的初始化方法里添加如下代码

for (id obj in self.subviews) {

if ([NSStringFromClass([obj class])

isEqualToString:@"UITableViewCellScrollView"])

{

UIScrollView *scroll = (UIScrollView *) obj; scroll.delaysContentTouches =NO; break; } } 

以上2步可以解决按钮没有点击效果的问题,但之后发现,如果滑动tableView的时候,触碰区域正好在按钮上的话,是滑动不了的。

这个时候就得

- (BOOL)touchesShouldCancelInContentView:(UIView *)view { return YES; }

本来以上方法在ios7以下可以解决,因为公司要适配ios8,当切换ios8的时候,发现又没有点击效果了,于是又查找一番.

第四步:在自定义的tableView初始化方法里添加如下代码

for (id view in self.subviews) { // looking for a UITableViewWrapperView if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewWrapperView"]) { if([view isKindOfClass:[UIScrollView class]]) { // turn OFF delaysContentTouches in the hidden subview UIScrollView *scroll = (UIScrollView *) view; scroll.delaysContentTouches = NO; } break; } }

或者第四步改成 在你的viewController添加tableview的时候,加上以下代码

 if ([UIDevice currentDevice].systemVersion.intValue >= 8)

{ for (UIView *currentView in table.subviews) {

if ([currentView isKindOfClass:[UIScrollView class]])

{ ((UIScrollView *)currentView).delaysContentTouches = NO; break; } } }