我正在尝试将用户为注册页面输入的信息存储到解析数据库中,但似乎无法弄清楚如何执行此操作。
class ViewController: UIViewController {
@IBOutlet var fullnameField: UITextField!
@IBOutlet var emailAddressField: UITextField!
@IBOutlet var usernameField: UITextField!
@IBOutlet var passwordField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let userFullname = fullnameField.text
let userEmailAddress = emailAddressField.text
let userName = usernameField.text
let userPassword = passwordField.text
let User = PFObject(className: "User")
User["FullName"] = "Example Name"
User["EmailAddress"] = "JohnDoe@example.com"
User["Username"] = "Example"
User["Password"] = "Ilovesmores12345"
User.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in
println("Object has been saved.")
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
当用户将他/她的信息输入到文本字段并点击注册时,我需要将信息保存到解析数据库中以便在登录页面中进一步使用。我觉得我在思考并使其变得更复杂,有没有办法轻松做到这一点?
答案 0 :(得分:0)
要注册,请勿使用user.save
- 使用user.signUpInBackgroundWithBlock
检查this link,这是解析iOS指南。
我的示例,创建一个按钮并将其连接到signUpPressed
方法。这是方法。
@IBAction func signUpPressed(sender: AnyObject) {
let userName = userNameField.text
let email = emailField.text.lowercaseString
let password = passwordField.text
let fullName = fullNameField.text
var user = PFUser()
user.username = userName
user.email = email
user.password = password
//for custom fields use default key-value assign
user["fullName"] = fullName
user.signUpInBackgroundWithBlock{ (succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as? String
// Show the errorString somewhere and let the user try again.
} else {
// Hooray! Let them use the app now.
}
}
}
我建议将对象的字段命名为小写字母,这样就不会与类名混淆。