vendredi 27 mai 2016

sender.tag in no set to 1 if user has Login in keychain?

I have create this logic for login button action.my problem if user has login and set sender.tag to loginButtonTag= 1 it will not run this code in "else if sender.tag == loginButtonTag".

@IBAction func signedInAction(sender: AnyObject)
{

    if (txtfUsername.text == "" || txtfPassword.text == "") {
         alert()
        return;
    }

    txtfUsername.resignFirstResponder()
    txtfPassword.resignFirstResponder()

    if sender.tag == createLoginButtonTag {
        let hasLoginKey = NSUserDefaults.standardUserDefaults().boolForKey("hasLoginKey")
        if hasLoginKey == false {                NSUserDefaults.standardUserDefaults().setValue(self.txtfUsername.text, forKey: "username")
        }


        keychain.set(txtfUsername.text!, forKey:kSecValueData as String)
        NSUserDefaults.standardUserDefaults().setBool(true, forKey: "hasLoginKey")
        NSUserDefaults.standardUserDefaults().synchronize()
        loginButton.tag = 1

        performSegueWithIdentifier("dismissLogin", sender: self)
    }
    else if sender.tag == loginButtonTag
    {
        if checkLogin(txtfUsername.text!, password: txtfPassword.text!)
        {
            performSegueWithIdentifier("dismissLogin", sender: self)
        }
        else
        {
            alert()
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire