-3

Back at it again with a noob question.

For some reason I get the following error:

2017-07-25 14:29:00.589401+0200 Yiives[1416:534883] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key UserEmailAdresLogin.'

Now I am way to green to see the problem on my own, so please enlighten me.

It will not let me load the Login View. So how can I make it happen :D

I run the following code:

import UIKit

class LoginViewController: UIViewController {

    @IBOutlet weak var BackgroundButton: UIButton!

    @IBOutlet weak var UserEmailAdresInput: UITextField!

    @IBOutlet weak var UserPasswordInput: UITextField!

    @IBOutlet weak var UserLogin: UIButton!

    @IBOutlet weak var UserForgotPassword: UIButton!


    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func CloseLogin(_ sender: Any) {

        dismiss(animated: true, completion: nil )
    }

    @IBAction func Login(_ sender: Any) {

        let UserEmail = UserEmailAdresInput.text
        let UserPassword = UserPasswordInput.text

        let UserEmailStored = UserDefaults.standard.string(forKey: "UserEmail");

        let UserPasswordStored = UserDefaults.standard.string(forKey: "UserPassword");

        if(UserEmailStored == UserEmail){
            if(UserPasswordStored == UserPassword){

                //Login is succesfull

                UserDefaults.standard.set(true, forKey: "UserLoggedIn")
                UserDefaults.standard.synchronize();

            }


        }
    }

}


If you need the source where the data is bein inserted:

import UIKit

class EntryViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var UserEmailAdresInput: UITextField!

    @IBOutlet weak var UserPasswordInput: UITextField!

    @IBOutlet weak var UserPasswordInputRepeated: UITextField!

    @IBOutlet weak var UserSignUp: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.UserEmailAdresInput.delegate = self
        self.UserPasswordInput.delegate = self
        self.UserPasswordInputRepeated.delegate = self


    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    //Hide Keyboard upon Touch

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
        self.view.endEditing(true)
    }

    //Hide Keyboard upon Return Key
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        if textField == UserEmailAdresInput{
            UserEmailAdresInput.resignFirstResponder()
        } else if textField == UserPasswordInput{
            UserPasswordInput.resignFirstResponder()
        } else {
            UserPasswordInputRepeated.resignFirstResponder()
        }
        return true
    }

    @IBAction func SignUp(_ sender: Any) {

        let UserEmail = UserEmailAdresInput.text;
        let UserPassword = UserPasswordInput.text;
        let UserPasswordRepeated = UserPasswordInputRepeated.text;



        //Check if fields are filled in correctly

        if(UserEmail?.isEmpty == true || UserPassword?.isEmpty == true || UserPasswordRepeated?.isEmpty == true){

            displayAlertMessage(userMessage: "Alle velden moeten ingevuld worden");
            return;
        }

        if UserEmail?.range(of: "@") == nil{
            displayAlertMessage(userMessage: "Vul een legitiem emailadres in");
            return;
        }

        if (UserPassword?.characters.count)! < 5{
            displayAlertMessage(userMessage: "Wachtwoord moet langer zijn dan 5 karakters");
        }

        if(UserPassword != UserPasswordRepeated){

            displayAlertMessage(userMessage: "Wachtwoorden zijn niet gelijk");
            return;
        }

        //Store Data
        UserDefaults.standard.set(UserEmail, forKey: "UserEmail");
        UserDefaults.standard.set(UserPassword, forKey: "UserPassword");
        UserDefaults.standard.synchronize();

        //SignUp Succesfull
        var Alert = UIAlertController(title:"Succesvol aangemeld!", message: "Ga naar je email inbox om je aanmelding te voltooien", preferredStyle: UIAlertControllerStyle.alert);

        let OkAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default, handler: nil);

        Alert.addAction(OkAction);
        self.present(Alert, animated: true, completion: nil)


    }

    func displayAlertMessage(userMessage:String){

        var Alert = UIAlertController(title:"Melding", message: userMessage, preferredStyle: UIAlertControllerStyle.alert);

        let OkAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default, handler: nil);

        Alert.addAction(OkAction);

        self.present(Alert, animated: true, completion: nil)

    }

}
devang bhatt
  • 460
  • 2
  • 15
vandernat.p
  • 153
  • 1
  • 1
  • 10
  • 3
    Check your storyboard and email outlet. You don't have any outlet named UserEmailAdresLogin in your code but apparently your Storyboard has it. did you create an outlet earlier with the name UserEmailAdresLogin and then deleted it? but forgot to delete from SB? – Kapil G Jul 25 '17 at 13:10
  • review your storyboard you must have a outlet linked in your storyboard that was removed from your related code – Reinier Melian Jul 25 '17 at 13:10
  • No not really. This was all I did. But I will check it – vandernat.p Jul 25 '17 at 13:12
  • if you already have outlet then delete them, drag them again. – Vaibhav Parmar Jul 25 '17 at 13:12
  • Click on your ViewController in your storyboard and then click on Connection inspector which is the rightmost icon with an arrow. See if that has any delegate named UserEmailAdresLogin. If yes see if you are using that delegate. Mostly you wont be. And if not then delete it. – Kapil G Jul 25 '17 at 13:15
  • Also, please rename `UserEmailAdresLogin` to `UserEmailAdressLogin`. :) – wottle Jul 25 '17 at 13:18
  • Yep it works now. Apparently not the only one I changed without realising it XD – vandernat.p Jul 25 '17 at 13:25

1 Answers1

1

This error means you have a link (I think in your storyboard file) to a variable called UserEmailAdresLogin but this variable no longer exists in your code source. To check it, right click on your controller in your storyboard, it will display the list of links, and just delete by clicking on the cross.

If the probleme is not in a storyboard, it's a typo in a variable name (by the way it should be written : "Address").

Maxime
  • 1,332
  • 1
  • 15
  • 43