我正在尝试根据用户登录信息是否正确来有条件地执行segue. 我从登录View Controller到新的导航控制器有一个模态segue. 我已经尝试过几乎所有我遇到过的建议,似乎没有任何工作.使用Sift和
我从登录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. } }这对我有用.两个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 } }