Вы можете реализовать свой собственный метод обратного вызова, чтобы сделать это.
Что я сделал, так это Я добавил TapGesture в customView. Когда событие вызывается, я использовал метод обратного вызова, чтобы передать элемент управления в viewController, где реализован мой tableView
Что вы можете сделать При загрузке заголовка вы можете присвоить значение тега для customView
customHeader.tag = 1;
и вы можете реализовать метод обратного вызова в вашем viewController.
В CustomheaderView
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checkBoxEventHandler:)];
[recognizer setNumberOfTapsRequired:1];
[recognizer setNumberOfTouchesRequired:1];
[self setGestureRecognizers:[NSArray arrayWithObject:recognizer]];
-(IBAction)checkBoxEventHandler:(id)sender
{
if ([self.delegate respondsToSelector:@selector(selectedHeader: atIndex:)])
{
[self.delegate selectedHeader:self atIndex:self.tag];
}
}
In your viewController.m
-(void)selectedHeader:(myCustomHeader *)header atIndex:(int)index
{
//header -> will give you the same instance you created in your viewController while loading this custom header view
// So you can check the tag like this
if(header.tag == 1)
{
//Do Stuff here
}
// index -> we are passing headerViews tag as index ie header.tag is equal to index
// So checking the tag like this is the proper way
if(index == 1)
{
//Do Stuff here
}
}