解决tableView上cell的按钮点击效果不明显(轻点无效)

来源:互联网 发布:实用记账软件 编辑:程序博客网 时间:2024/06/10 05:38

在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


但是在ios7中,这种办法就失去了效果,因为在ios7中,tableviewcell中也有scrollView的子类,因此需要对cell进行遍历:

-(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循环代码贴上.



0 0
原创粉丝点击