Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import CoreData
- class ViewResults: UIViewController {
- //links username text field
- @IBOutlet weak var usernameTextField: UITextField!
- //links password text field
- @IBOutlet weak var passwordTextField: UITextField!
- //links "ok" button
- @IBOutlet weak var okBtn: UIButton!
- override func viewDidLoad() {
- super.viewDidLoad()
- }
- @IBAction func okButton(_ sender: Any) {
- //user can only view results if the username = admin and password = hello
- if usernameTextField.text == "admin" && passwordTextField.text == "hello"
- {
- //alert pop up if login successful
- let alertController = UIAlertController(title: "Login Successful!", message:
- "Press Ok to view the results", preferredStyle: .alert)
- //takes user to results page if login is successful and user presses OK in alert
- alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in self.performSegue(withIdentifier: "results", sender: self) } ))
- self.present(alertController, animated: true, completion: nil)
- //debugging code outputs to console so I can check if login successful
- NSLog("Login successful")
- }
- else
- {
- //debugging code outputs to console so I can check if login failed
- NSLog("Login failed")
- //alert pop up if login fails
- let alertController = UIAlertController(title: "Incorrect Password!", message:
- "Please enter the correct password", preferredStyle: .alert)
- alertController.addAction(UIAlertAction(title: "Try Again", style: .default))
- self.present(alertController, animated: true, completion: nil)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement