I wanna make it like, touch the section header then jump to end of this section. How could I do it? Any suggestions? Cheers
- (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;
}
}
Implement method - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
in your delegate. In this method create UIView
with needful subviews (labels, images and etc.). At the end just add UITapGestureRecognizer
to that view. And then return it it.
For example:
- (IBAction)sectionTapped:(UITapGestureRecognizer *)recognizer
{
switch (recognizer.view.tag) {
case 0:
// do what you want for section with index 0
break;
default:
break;
}
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UILabel *label;
label.text = [NSString stringWithFormat:@"Section %d", section];
label.tag = section;
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sectionTapped:)];
[label addGestureRecognizer:recognizer];
[recognizer release];
return label;
}