Reputation: 43
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.
}
}
Upvotes: 4
Views: 3138
Reputation: 1
well!!! i had done sorry for my english, but here is my final code with parse Login it always say " Variable "variableName" Was never mutated but it work if you could help me with that....
@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
}
})
}
i hope it could help
Upvotes: 0
Reputation: 1
well this is my first time i hope it will help
i did an offline Signup metho for triyng but i think the objective is the same
my code for conditional segue was this
@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
}
}
well i hope it can't help you now i will try with the internet login well the is the section of the "StoryBoard ID" on the top right, look for "UsuarioPerfil" There
Upvotes: 0
Reputation: 19524
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
}
}
Upvotes: 1