标签:tap .text 单元格 ini should round integer control ace
#import "ViewController.h" @interface ViewController ()<UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate> @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIView * v = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 280, 100)]; v.backgroundColor = [UIColor redColor]; [self.view addSubview:v]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewClick:)]; tap.delegate = self; [v addGestureRecognizer:tap]; UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 280, 100)]; tableView.delegate = self; tableView.dataSource = self; [v addSubview:tableView]; } -(void) viewClick:(UITapGestureRecognizer*) tap { NSLog(@"点击view"); } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell * cell = [UITableViewCell new]; cell.textLabel.text = @"測试"; return cell; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"点击单元格"); } #pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { // 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件 if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) { return NO; } return YES; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
下面是代码
UIView加入手势 然后UITableView 加入进这个View 导致UITableView 的单元格点击事件无效
标签:tap .text 单元格 ini should round integer control ace
原文地址:http://www.cnblogs.com/yxysuanfa/p/6927077.html