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 h
Here is what worked for me in Swift 2:
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let footerView = UITableViewHeaderFooterView()
footerView.textLabel?.text = "Header Text"
let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap))
tapRecognizer.delegate = self
tapRecognizer.numberOfTapsRequired = 1
tapRecognizer.numberOfTouchesRequired = 1
footerView.addGestureRecognizer(tapRecognizer)
return footerView
}
@objc func handleTap(gestureRecognizer: UIGestureRecognizer) {
print("Tapped")
}