在ios8中,可以让tableview继承一个baseTabelView父类,在父类的.,m文件中重写以下方法:
#import "BaseTableView.h"
@implementation BaseTableView
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
self.delaysContentTouches = NO;
// iterate over all the UITableView's subviews
for (id view in self.subviews)
{
// looking for a UITableViewWrapperView
if ([NSStringFromClass([view class]) isEqualToString:@"UITableViewWrapperView"])
{
// this test is necessary for safety and because a "UITableViewWrapperView" is NOT a UIScrollView in iOS7
if([view isKindOfClass:[UIScrollView class]])
{
// turn OFF delaysContentTouches in the hidden subview
UIScrollView *scroll = (UIScrollView *) view;
scroll.delaysContentTouches = NO;
}
break;
}
}
}
return self;
}
@end
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
for (UITableViewCell *cell in self.tableView.visibleCells) {
for (id obj in cell.subviews)
{
if ([NSStringFromClass([obj class]) isEqualToString:@"UITableViewCellScrollView"])
{
UIScrollView *scroll = (UIScrollView *) obj;
scroll.delaysContentTouches = NO;
break;
}
}
}
}以上代码我用在storyboard拖的tableview控制器中,类别为静态cell.而对于动态的cell,则可以在datasource的代理方法
cellForRowAtIndexPath中将上述forin循环代码贴上.
本文介绍了在iOS8环境下,如何通过创建一个baseTableView父类,并在父类中重写`cellForRowAtIndexPath`方法来解决tableView上cell内按钮点击效果不明显或者点击无响应的问题。
1万+

被折叠的 条评论
为什么被折叠?



