我想让它变成这样,触摸部分标题,然后跳到本节的结尾。我怎么能这样做?有什么建议么?欢呼声我们如何才能使节标题在UITable中可触?
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
[headerView setBackgroundColor:[[UIColor grayColor] colorWithAlphaComponent:0.7]];
UILabel *titleInSection = [[[UILabel alloc] initWithFrame:CGRectMake(50, 3, tableView.bounds.size.width/3, 20)] autorelease];
[titleInSection setBackgroundColor:[[UIColor grayColor] colorWithAlphaComponent:0]];
[titleInSection setTextColor:[UIColor whiteColor]];
if (isSectionLoad == YES){
[categoryData retain];
titleInSection.text = [categoryData objectAtIndex:section];
}
titleInSection.tag = section;
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionTapped:)];
[titleInSection addGestureRecognizer:recognizer];
[recognizer release];
[headerView addSubview:titleInSection];
return headerView;
}
- (IBAction)sectionTapped:(UITapGestureRecognizer *)recognizer
{
switch (recognizer.view.tag) {
case 0:
// do what you want for section with index 0
NSLog(@"HELLO WORLD!!!");
break;
default:
break;
}
}
请注意,0是标签属性的默认值。我建议添加一个常数偏移量。 –
正如Nekto所说,添加识别器到headerView,并设置属性headerView.userInteractionEnabled = YES;因为在我的代码中,我添加了动作触发器来标记,但它应该在部分标题的视图中。 – david