我已经调用了函数,它仍然没有显示我收到的代码权限和错误使用局部变量' displayAlert'在宣布之前
import UIKit
import FirebaseAuth
class ViewController: UIViewController {
// I have also switched the @IBAction to function so the code actually run better any suggestions to fix this
@IBOutlet weak var dropoffLabel: UILabel!
@IBOutlet weak var pickupLabel: UILabel!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var emailTextfield: UITextField!
@IBOutlet weak var pickupDropoffSwitch: UISwitch!
@IBOutlet weak var buttomButton: UIButton!
@IBOutlet weak var topButton: UIButton!
var signUpMode = true
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func topTapped(_ sender: Any) {
if emailTextfield.text == "" || passwordTextField.text == "" {
code error coming from here ----> displayAlert(title: "Missing Information", message: "You must provide both a email and password")
} else {
if let email = emailTextfield.text {
if let password = passwordTextField.text {
if signUpMode {
// SIGN UP
Auth.auth().createUser(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
displayAlert(title: "Error", message: error!.localizedDescription)
} else {
print("Sign Up Success")
}
})
} else {
// LOG IN
Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
displayAlert(title: "Error", message: error!.localizedDescription)
} else {
print("Sign Up Success")
}
})
}
}
}
}
------> I believe if I am doing it correctly called the function here func displayAlert(title:String, message:String) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
//there is no other issue besides the code not understanding the the function I have labeled
//Also I have ran the code before and the alert would pop up but now it is not allowing the
func buttomTapped(_ sender: Any) {
if signUpMode {
topButton.setTitle("Log In", for: .normal)
buttomButton.setTitle("Switch to Sign Up", for: .normal)
pickupLabel.isHidden = true
dropoffLabel.isHidden = true
pickupDropoffSwitch.isHidden = true
signUpMode = false
} else {
topButton.setTitle("Sign Up", for: .normal)
buttomButton.setTitle("Switch to Log In", for: .normal)
pickupLabel.isHidden = false
dropoffLabel.isHidden = false
pickupDropoffSwitch.isHidden = false
signUpMode = true
}
}
}
}
答案 0 :(得分:0)
您在topTapped func中错误地定义了displayAlert功能。
你需要把它移到外面,所以它在课堂上
@IBAction func topTapped(_ sender: Any) {
//code here
}
func displayAlert(title:String, message:String) {
//
}