Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. @IBOutlet weak var usernameField: UITextField!
  2. @IBOutlet weak var passwordField: UITextField!
  3.  
  4. var actInd : UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(0,0, 150, 150)) as UIActivityIndicatorView
  5.  
  6. override func viewDidLoad() {
  7. super.viewDidLoad()
  8.  
  9. self.actInd.center = self.view.center
  10. self.actInd.hidesWhenStopped = true
  11. self.actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
  12. view.addSubview(self.actInd)
  13.  
  14. }
  15.  
  16. override func didReceiveMemoryWarning() {
  17. super.didReceiveMemoryWarning()
  18. // Dispose of any resources that can be recreated.
  19. }
  20.  
  21.  
  22. /*
  23. // MARK: - Navigation
  24.  
  25. // In a storyboard-based application, you will often want to do a little preparation before navigation
  26. override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  27. // Get the new view controller using segue.destinationViewController.
  28. // Pass the selected object to the new view controller.
  29. }
  30. */
  31.  
  32. // MARK: Actions
  33.  
  34. @IBAction func loginAction(sender: AnyObject) {
  35.  
  36. var username = self.usernameField.text
  37. var password = self.passwordField.text
  38.  
  39. if (username.utf16Count < 4 || password.utf16Count < 5) {
  40.  
  41. var alert = UIAlertView(title: "Invalid", message: "Username must be greater then 4 and Password must be greater then 5", delegate: self, cancelButtonTitle: "OK")
  42. alert.show()
  43.  
  44. }else {
  45.  
  46. self.actInd.startAnimating()
  47.  
  48. PFUser.logInWithUsernameInBackground(username, password: password, block: { (user, error) -> Void in
  49.  
  50. self.actInd.stopAnimating()
  51.  
  52. if ((user) != nil) {
  53.  
  54. var alert = UIAlertView(title: "Success", message: "Logged In", delegate: self, cancelButtonTitle: "OK")
  55. alert.show()
  56.  
  57. }else {
  58.  
  59. var alert = UIAlertView(title: "Error", message: "(error)", delegate: self, cancelButtonTitle: "OK")
  60. alert.show()
  61.  
  62. }
  63.  
  64. })
  65.  
  66. }
  67.  
  68. }
  69.  
  70. @IBAction func signUpAction(sender: AnyObject) {
  71.  
  72. self.performSegueWithIdentifier("signUp", sender: self)
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement