大佬教程收集整理的这篇文章主要介绍了ios – 为tableView标头添加手势识别器不起作用?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
代码很简单:
- (void)tap:(UITapGestureRecognizer *)recognizer { // do something } UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@SELEctor(tap:)]; [self.tableView.tableHeaderView addGestureRecognizer:recognizer];
这里有任何提示要关心吗?非常感谢
self.tableView.tableHeaderView
我在tableview上的每个UILabel上添加了手势识别器.
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UILabel *headerLabel = [[UILabel alloc]init]; headerLabel.tag = section; headerLabel.userInteractionEnabled = YES; headerLabel.BACkgroundColor = [UIColor greenColor]; headerLabel.text = [NSString StringWithFormat:@"Header No.%d",section]; headerLabel.frame = CGRectMake(0,tableView.tableHeaderView.frame.size.width,tableView.tableHeaderView.frame.size.height); UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@SELEctor(catchHeaderGesture:)]; tapGesture.cancelsTouchesInView = NO; [headerLabel addGestureRecognizer:tapGesture]; return headerLabel; //return nil; } -(void)catchHeaderGesture:(UIGestureRecognizer*)sender { UILabel *caughtLabel = (UILabel*)sender.view; NSLog(@"header no : %d",caughtLabel.tag); }
我希望有所帮助.
以上是大佬教程为你收集整理的ios – 为tableView标头添加手势识别器不起作用?全部内容,希望文章能够帮你解决ios – 为tableView标头添加手势识别器不起作用?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。