登录表格在swift中

时间:2015-06-05 06:34:59

标签: ios swift

你们可以用一些代码帮助我吗?我在xcode 6.3中有注册表单,我希望如果用户名和密码是< 5然后无法进一步下一步登录视图控制器。代码在这里:

//
//  CustomSignupViewController.swift
//  CustomLogin
//
//  Created by PJ Vea on 3/11/15.
//  Copyright (c) 2015 Vea Software. All rights reserved.
//

import UIKit
import Parse

class CustomSignupViewController: UIViewController {

@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var usernameField: UITextField!
@IBOutlet weak var passwordField: UITextField!

var actInd : UIActivityIndicatorView = UIActivityIndicatorView(frame: CGRectMake(0,0, 150, 150)) as UIActivityIndicatorView

override func viewDidLoad() {
    super.viewDidLoad()

    self.actInd.center = self.view.center
    self.actInd.hidesWhenStopped = true
    self.actInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
    view.addSubview(self.actInd)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}





// MARK: Actions

@IBAction func signUpAction(sender: AnyObject) {

    var username = self.usernameField.text
    var password = self.passwordField.text
    var email = self.emailField.text

    if count(username) < 4 || count(password) < 5 {

        var alert = UIAlertView(title: "Invalid", message: "Username must be greater then 4 and Password must be greater then 5", delegate: self, cancelButtonTitle: "OK")
        alert.show()

    }else if count (email) < 8 {

        var alert = UIAlertView(title: "Invalid", message: "Please enter a valid password.", delegate: self, cancelButtonTitle: "OK")
        alert.show()


    }else {

        self.actInd.startAnimating()

        var newUser = PFUser()
        newUser.username = username
        newUser.password = password
        newUser.email = email

        newUser.signUpInBackgroundWithBlock({ (succeed, error) -> Void in

            self.actInd.stopAnimating()

            if ((error) != nil) {

                var alert = UIAlertView(title: "Error", message: "\(error)", delegate: self, cancelButtonTitle: "OK")
                alert.show()

            }else {

                var alert = UIAlertView(title: "Success", message: "Signed Up and Logged In", delegate: self, cancelButtonTitle: "OK")
                alert.show()

            }

        })

    }

}
}

我将非常感谢你的回答! :)

1 个答案:

答案 0 :(得分:1)

如果您在Storyboard中设置了segue,请为segue指定一个标识符。 (比如,yourID

然后调用以下方法。

self.performSegueWithIdentifier("yourId", sender: self)

当你想要转到下一个ViewController时。

修改

在最后的其他地方调用该方法。

}else {

    self.actInd.startAnimating()

    var newUser = PFUser()
    newUser.username = username
    newUser.password = password
    newUser.email = email

    self.performSegueWithIdentifier("yourId", sender: self)
    newUser.signUpInBackgroundWithBlock({ (succeed, error) -> Void in