Swift 3 Unrecognized selector posted to UIButton instance

I am getting this error:

Application terminated due to uncaught exception 'NSInvalidArgumentException', reason: '- [UITouchesEvent text]: unrecognized selector sent to instance 0x6100000e9400'

The button it falls from:

import UIKit
import Firebase
import FBSDKLoginKit

class RegisterViewController: UIViewController, FBSDKLoginButtonDelegate, UITextFieldDelegate {

    override func viewDidLoad() {
    super.viewDidLoad()
        // Create Sign Up button
        let signUpButton: UIButton = {
            let button = UIButton()
            button.setImage(#imageLiteral(resourceName: "Go Button@1x"), for: .normal)
            button.addTarget(self, action: #selector(createAccountTapped), for: .touchUpInside) // when tapped on Sign In button, execute function SignInTapped
            button.translatesAutoresizingMaskIntoConstraints = false
            return button
            }()
        func signUpButtonView() {
            signUpButton.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
            signUpButton.heightAnchor.constraint(equalToConstant: 70).isActive = true
            signUpButton.widthAnchor.constraint(equalTo: view.widthAnchor, constant: 0).isActive = true
            signUpButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
        }

        self.view.addSubview(signUpButton)
        signUpButtonView()

    }

    func createAccountTapped(_ usernameTextField: UITextField, passwordTextField: UITextField, repeatPasswordTextField: UITextField) {
        let username = usernameTextField.text
        let password = passwordTextField.text
        let repeatPassword = repeatPasswordTextField.text
    }
}

      

I have another button for Facebook registration and it works great ... I think it has something to do with the parameters in the function createAccountTapped

, but I don't know what happened.

-4


source to share


1 answer


You cannot pass an instance UITextField

with an action UIButton

, you can only set those actions createAccountTapped()

and createAccountTapped(_ sender: UIButton)

with UIButton

.



If you want to access textField

in your action UIButton

, you need to create IBOutlet

for this textField

in RegisterViewController

.

+3


source







All Articles