通过索引攻丝UITableViewHeader
我想获取索引时点击UITableView
标题。现在,我没有添加UIGestureRecognizer
到标题那样:通过索引攻丝UITableViewHeader
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionTapped:)];
UIView *headerView = [UIView new];
headerView.backgroundColor = [UIColor grayColor];
[headerView addGestureRecognizer:recognizer];
// return [self.myTableView headerWithTitle:self.headers[section] totalRows:self.cells.count inSection:section];
return headerView;
}
-(IBAction)sectionTapped:(id)sender{
NSLog(@"tapped header");
}
是否有简便的方式来传递部分Index
上自来水?
一套标记为您headerview
像headerView.tag = section;
- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionTapped:)];
UIView *headerView = [UIView new];
headerView.tag = section;
headerView.backgroundColor = [UIColor grayColor];
[headerView addGestureRecognizer:recognizer];
// return [self.myTableView headerWithTitle:self.headers[section] totalRows:self.cells.count inSection:section];
return headerView;
}
-(IBAction)sectionTapped:(UITapGestureRecognizer *)recognizer{
NSLog(@"tapped header==%d",recognizer.view.tag);
NSLog(@"tapped header == %ld", recognizer.view.tag);
}
用于替代看到this
谢谢,那会做。 –
'NSLog(@“tapped header ==%@”,recognizer.view.tag);'会抛出异常,因为标记是NSInteger。 – Igor
@Igor - 我更新了答案检查一次我的兄弟, –
添加标签:
recognizer.view.tag = section;
,并得到:
- (IBAction)sectionTapped:(UITapGestureRecognizer *)recognizer{
NSLog(@"tapped header %d", recognizer.view.tag);
}
谢谢你,那工作。 –
是你的隔宿ture is works –