快速定制segue条件

时间:2014-10-16 23:22:06

标签: swift xcode6 segue

我试图根据用户登录信息是否正确来有条件地执行segue。

我从登录View Controller到新的导航控制器有一个模态segue。

我已经尝试过几乎所有我遇到过的建议,似乎没有任何效果。使用Sift和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.
 }

}

3 个答案:

答案 0 :(得分:1)

这对我有用。两个UITextFields和一个UIButton以及从VC到VC2的模态segue:

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 :(得分:0)

这是我第一次希望它会有所帮助

我为triyng做了一个离线注册方法,但我认为目标是相同的

条件segue的代码就是这个

/storage/emulated/0/testcopy.mp4: open failed: EISDIR (Is a directory)

我希望它现在无法帮助您,我会尝试使用互联网登录 well the is the section of the "StoryBoard ID" on the top right, look for "UsuarioPerfil" There

答案 2 :(得分:0)

阱!!!我为我的英语做了对不起,但这是我的最后一个代码,用解析登录它总是说“变量”变量名称“从来没有变异但是如果你可以帮助我那就有效....

    @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
            }
        })


}

我希望它可以提供帮助