In the init function the #selector can't seem to find the calling function.
Here is the class
import UIKit
protocol ExpandableHeaderViewDelegate {
func toggleSection(header: ExpandableHeaderView, section: Int)
}
class ExpandableHeaderView: UITableViewHeaderFooterView {
var delegate: ExpandableHeaderViewDelegate?
var section: Int!
@IBOutlet weak var titleLabel: UILabel!
override init(reuseIdentifier: String?){
super.init(reuseIdentifier: reuseIdentifier)
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(_:))))
}
@objc func selectHeaderView(gesture: UITapGestureRecognizer){
let cell = gesture.view as! ExpandableHeaderView
delegate?.toggleSection(header: self, section: cell.section)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(_:))))
}
func custonInt(title: String, section: Int, delegate: ExpandableHeaderViewDelegate){
self.titleLabel.text = title
self.section = section
self.delegate = delegate
}
override func layoutSubviews(){
super.layoutSubviews()
self.titleLabel.textColor = UIColor.white
self.contentView.backgroundColor = UIColor.darkGray
}
}
Here is the error:
Use of unresolved identifier 'selectHeaderView'
the init function add gesture recognizer can't find selectHeaderView. Its acting as if its not part of the class. What am I doing wrong?
Change this:
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(_:))))
to:
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(gesture:))))
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