Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#selector unresolved identifier function

Tags:

swift

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?

like image 693
steller Avatar asked Jul 09 '26 11:07

steller


1 Answers

Change this:

self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(_:))))

to:

self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(selectHeaderView(gesture:))))
like image 184
Nerdy Bunz Avatar answered Jul 12 '26 06:07

Nerdy Bunz