Fast customs shutdown provided

I am trying to conditionally execute segue depending on whether the login information is correct.

I have a modal transition from my login controller to the new navigation controller.

I tried almost every sentence that I came across, and nothing worked. Using Sift and Xcode 6.

import UIKit

import AudioToolbox

class ViewController: UIViewController {

   @IBOutlet weak var usernameTextField: UITextField!

   @IBOutlet weak var passwordTextField: UITextField!

   @IBOutlet weak var incorrectCredentialLabel: UILabel!

   @IBAction func loginAction(sender: UIButton) {

       var username = "test"
       var password = "code"

       println("Username: " + usernameTextField.text)
       println("Password: " + passwordTextField.text)

       if usernameTextField.text == username &&
          passwordTextField.text == password {

          usernameTextField.resignFirstResponder()
          passwordTextField.resignFirstResponder()

          println("Login Status: success")

       self.shouldPerformSegueWithIdentifier("loginSegue", sender: nil)

    } else {

         usernameTextField.resignFirstResponder()
         passwordTextField.resignFirstResponder()

         AudioServicesPlayAlertSound(1352)
        /*AudioServicesPlayAlertSound(kSystemSoundID_Vibrate)*/

         incorrectCredentialLabel.text = "username or password is incorrect"
         incorrectCredentialLabel.textColor = UIColor.redColor()

         println("Login Status: failed")
    }
}

 override func viewDidLoad() {
     super.viewDidLoad()
     // Do any additional setup after loading the view, typically from a nib.
 }

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

}
+4
source share
3 answers

It worked for me. Two UITextFields and UIButton together with a modal segment from VC to VC2:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    let userName = "John"
    let passCode = "123"

    @IBOutlet weak var Name: UITextField!

    @IBOutlet weak var Pass: UITextField!
    @IBAction func tapButton(sender: UIButton) {

        if self.Name.text == "John" && self.Pass.text == "123" {

         performSegueWithIdentifier("nextView", sender: self)
        }
    }

    //ViewController lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()

        self.Name.delegate = self
        self.Pass.delegate = self

    }
}
+1
source

Well, this is my first time, I hope this helps

I made a standalone registration method for triyng, but I think the goal is the same

My code for conditional segue was

@IBAction func LoginPressed(sender: UIButton) {

/*previously assigned by the app owner for the customer it is saved in the app code so it is in the phone memory(?)*/
        if RutField.text == "243338743"  && CodigoField.text == "1104"{
            /*i'm not sure what this but is kind of a dialogue of what came first and later, You must previously assign the ViewController Identity on the "StoryBoard ID" it will help any doubt or image help contact me*/
            dispatch_async(dispatch_get_main_queue()){
                var Storyboard = UIStoryboard(name: "Main", bundle: nil)
                var PerfilUsuario : UIViewController = Storyboard.instantiateViewControllerWithIdentifier("PerfilUsuario") as! UIViewController
                self.presentViewController(PerfilUsuario, animated: true, completion: nil)
            }
        }
        else {
            TrekLogo.hidden = true
        }
}

, , - , "StoryBoard ID" , "UsuarioPerfil"

0

OK!!! I apologized for my English, but here is my last parsing code. Login always says "Variable" variableName "Never mutated, but it works if you could help me with this ....

    @IBAction func LoginPressed(sender: UIButton) {

        var User = PFUser()

        User.username = RutField.text
        User.password = CodigoField.text

        PFUser.logInWithUsernameInBackground(RutField.text!, password: CodigoField.text!, block:{(User : PFUser?, Error : NSError?) -> Void in

            if Error == nil {

                dispatch_async(dispatch_get_main_queue()){
                    var Storyboard = UIStoryboard(name: "Main", bundle: nil)
                    var PerfilUsuario : UIViewController = Storyboard.instantiateViewControllerWithIdentifier("PerfilUsuario") as! UIViewController
                    self.presentViewController(PerfilUsuario, animated: true, completion: nil)
                }
            }
            else {
                self.TrekLogo.hidden = true
            }
        })


}

Hope this helps

0
source

All Articles