I have a button in my view class attempting to add a selector function from a separate class as follows:
class ProfileView: UIView {
createAccountButton.addTarget(self, action: #selector(ProfileViewController.createAccountClicked), for: .touchUpInside)
}
class ProfileViewController: UIViewController {
func createAccountClicked() {
print("button press")
}
}
I am getting a unrecognized selector error when I am trying to reference this method outside of ProfileView
. However it works when I simply put createAccountClicked()
into ProfileView
and call:
createAccountButton.addTarget(self, action: #selector(self.createAccountClicked), for: .touchUpInside)
instead. My question is - Is it possible to call a function from a separate class? Or would just having the function in the same class be the correct design pattern to follow?