đây là button
của tôi đối tượnglàm thế nào để sử dụng phương pháp addTarget trong nhanh chóng 3
let loginRegisterButton:UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = UIColor(r: 50 , g: 80, b: 130)
button.setTitle("Register", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.setTitleColor(.white, for: .normal)
button.addTarget(self, action:#selector(handleRegister), for: .touchUpInside)
return button
}()
và đây là chức năng của tôi
func handleRegister(){
FIRAuth.auth()?.createUser(withEmail: email, password: password,completion: { (user, error) in
if error != nil
{ print("Error Occured")}
else
{print("Successfully Authenticated")}
})
}
Tôi nhận được biên dịch lỗi, nếu addTarget loại bỏ nó biên dịch thành công
Hãy thử này 'button.addTarget (bản thân, hành động: #selector (handleRegister()), cho: .touchUpInside)'. – VRAwesome
'handleRegister' hành động trong cùng một bộ điều khiển? Ngoài ra, bạn không đặt khung 'UIButton'. –
có, tôi có một hàm khác cho các ràng buộc func ràng buộc của nó() {loginRegisterButton.centerXAnchor.constraint (bằngTo: inputview.centerXAnchor) .isActive = true loginRegisterButton.topAnchor.constraint (equalTo: inputview.bottomAnchor, constant: 12) .isActive = true loginRegisterButton.widthAnchor.constraint (bằngTo: inputview.widthAnchor) .isActive = true loginRegisterButton.heightAnchor.constraint (equalToConstant: 30) .isActive = true} – Ninja13