为什么我的应用在尝试登录时崩溃(firebase 登录)

时间:2021-05-20 14:44:54

标签: ios swift iphone xcode ios14

<块引用>

错误:由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[Stylor.LoginViewController LoginButton:]: 无法识别的选择器发送到实例 0x147d0a8f0'

代码:

import UIKit
import Firebase

class LoginViewController: UIViewController {

@IBOutlet var emailTextField: UITextField!
@IBOutlet var passwordTextField: UITextField!


override func viewDidLoad() {
    super.viewDidLoad()
    
    // Hide Keyboard (G:UIViewController - F:dismissKeyboard.swift)
    self.hideKeyboardWhenTapped()
    self.hideKeyboardOnSwipeDown()
    self.hideKeyboardOnSwipeUp()
    
    
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

// MARK: Disable Rotation of UIViewController
override open var shouldAutorotate: Bool {
       return false
}


@IBAction func LoginButtonTapped(_ sender: Any) {
    
    // Validate the input
    guard let email = emailTextField.text, email != "",
          let password = passwordTextField.text, password != "" else {
        
        let alertController = UIAlertController(title: "Login Error", message: "Login Error", preferredStyle: .alert)
        let okayAction = UIAlertAction(title: "Ok", style: .cancel, handler: nil)
        
        alertController.addAction(okayAction)
        present(alertController, animated: true, completion: nil)
        
        return
    }
    
    // Register the user account on Firebase
    Auth.auth().signIn(withEmail: email, password: password, completion: { (user, error) in
        
        if let error = error {
            let alertController = UIAlertController(title: "Login Error", message: error.localizedDescription, preferredStyle: .alert)
            let okayAction = UIAlertAction(title: "Ok", style: .cancel, handler: nil)
            
            alertController.addAction(okayAction)
            self.present(alertController, animated: true, completion: nil)
            
            return
        }
        
        // Dismiss Keyboard
        self.view.endEditing(true)
        
        
        // Present the MainTabBarViewController
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let vc = storyboard.instantiateViewController(identifier: "MainTabBarViewController")   
        vc.modalPresentationStyle = .overFullScreen
        self.present(vc, animated: true)
        
    })
}
}

当我使用 firebase 创建用户时,它可以正常工作,但是当我尝试使用相同的凭据登录时,它会崩溃并给出上述错误。感谢您的帮助,祝您度过愉快的一天。

1 个答案:

答案 0 :(得分:0)

替换

@IBAction func LoginButtonTapped(_ sender: Any) {

@IBAction func LoginButton(_ sender: Any) {
相关问题