I have a UITableView
with multiple sections. Each section has a section header (a custom view) is there an easy way to detect when someone selects the section header? (Just like didSelectRowAtIndexPath
, but for the header?)
tableView(_:titleForHeaderInSection:) Asks the data source for the title of the header of the specified section of the table view.
If you need to make the footer view fixed at the bottom then you can not use a TableViewController . You will have to use UIViewController , put your tableView as a subview. Put the footer also as another subview and its done.
This isn't radically different than @rckoenes answer, but it does provide a more orthodox way of handling events on views rather than using invisible buttons.
I'd rather add a UITapGestureRecognizer to my header view instead of adding invisible buttons and resizing them:
UITapGestureRecognizer *singleTapRecogniser = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)] autorelease]; [singleTapRecogniser setDelegate:self]; singleTapRecogniser.numberOfTouchesRequired = 1; singleTapRecogniser.numberOfTapsRequired = 1; [yourHeaderView addGestureRecognizer:singleTapRecogniser];
and then:
- (void) handleGesture:(UIGestureRecognizer *)gestureRecognizer;
You can use gesture.view to see which was touched. Then do whatever you need to do to find out which header it was (tags, data array lookup... )
No there is no way to do it with the UITableViewDelegate
.
What you can do is to add a button the size of the section header view and add it to the view. Set the tag of the button to the section index. Then just add the UIViewController
as a target for the UIControlEventTouchUpInside
.
Then by looking at the tag of the button you can see which section is clicked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With