I'm trying to conditionally execute a segue based on whether or not a users login information is correct.
I have a modal segue from my login View Controller to a new Navigation Controller.
I've tried pretty much every suggestion I've come across and nothing has seemed to work. 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.
}
}
This worked for me. Two UITextFields and a UIButton along with a modal segue 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
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments