There is no way to do it with the UITableViewDelegate.
You have to add a UITapGestureRecognizer to yourHeaderView Like:
UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandler:)];
[singleTapRecognizer setDelegate:self];
singleTapRecognizer.numberOfTouchesRequired = 1;
singleTapRecognizer.numberOfTapsRequired = 1;
[yourHeaderView addGestureRecognizer:singleTapRecognizer];
-(void) handleGesture:(UIGestureRecognizer *)gestureRecognizer; //do in this method whatever you want
FOR Swift 3.0
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(YOURVIEWCONTROLLER.TapGestureRecognizer(_:)))
yourHeaderView.addGestureRecognizer(tapGesture)
func TapGestureRecognizer(gestureRecognizer: UIGestureRecognizer) {
//do your stuff here
}
Swift >= 4.0
Add UIGestureRecognizerDelegate class reference inherited
let tap = UITapGestureRecognizer(target: self, action:#selector(self.handleTap(_:)))
tap.delegate = self
self.view.addGestureRecognizer(tap)
@objc func handleTap(_ sender: UITapGestureRecognizer) {
//Do your work
}
may be it will help.
Happy Coding.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…