pls do not mark this question as duplicate as I have tried the various solutions but doesn't quite work. I am creating a headerView in my FormViewController (I'm using Eureka) and I separated my views into a separate HeaderViews: NSObject
to observe the MVC principle. I attempted to add a buttonTarget but it throws the error unrecognized selector sent to class
. My code as follows:
class ProfileSettingsViewController: FormViewController {
override func viewDidLoad() {
super.viewDidLoad()
form +++
Section(){ section in
section.header = {
var header = HeaderFooterView<UIView>(.callback({
let view = HeaderViews.setUpHeaderForProfileView(user: self.user)
return view
}))
header.height = { 200 }
return header
}()
}
}
And in my HeaderViews:
class HeaderViews: NSObject {
static func setUpHeaderForProfileView(user: User) -> UIView {
let view = UIView(frame: CGRect(x: 0, y: 0, width: screen.width, height: 100))
let changeAvatarButton = UIButton(frame: CGRect(x: (screen.width / 2) - 50, y: avatarImageView.frame.maxY + 10, width: 100, height: 20))
changeAvatarButton.addTarget(self, action: #selector(getAvatar(_:)), for: .touchUpInside)
view.addSubview(changeAvatarButton)
return view
}
func getAvatar(_ sender: UIButton!) {
print("Change Avatar tapped")
}
}
I'm not quite sure if I have made any mistake, as I have tried various methods of the selectors in this post: Unrecognized selector sent to class
I suspect it might something to do with the subclass NSObject. Any advice pls?