我有多个 View Controller 。
第一个是带有用户名和密码文本字段的登录页面。我在哪里使用 Parse 注册用户:
- (IBAction)signup:(id)sender{
PFUser *user = [PFUser user];
user.username = _username.text;
user.password = _password.text;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
} else {
[self dismissModalViewControllerAnimated:YES];
NSLog(@"already username");
[self.navigationController popToRootViewControllerAnimated:YES];
_username.textColor = [UIColor redColor];
_inuse.text = @"Username is already taken!";
// Show the errorString somewhere and let the user try again.
}
}];
}
然后在下一个 View Controller 上,我想向用户添加信息。
所以我尝试在下一个 View Controller 上执行此操作。我有两个文本字段 firstname
和 lastname
:
- (IBAction)signup_name:(id)sender{
PFUser *user = [PFUser user];
user[@"firstname"] = _firstname.text;
user[@"lastname"] = _lastname.text;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
} else {
[self dismissModalViewControllerAnimated:YES];
NSLog(@"already username");
[self.navigationController popToRootViewControllerAnimated:YES];
_username.textColor = [UIColor redColor];
_inuse.text = @"Username is already taken!";
// Show the errorString somewhere and let the user try again.
}
}];
}
但我收到错误消息:“用户无法保存,除非他们已经注册。先打电话注册。”
我尝试将此添加到 - (IBAction)signup:(id)sender
当没有 error
时:
[PFUser logInWithUsernameInBackground:_username.text password:_password.text
block:^(PFUser *user, NSError *error) {
if (user) {
// Do stuff after successful login.
} else {
// The login failed. Check error to see why.
}
}];
最佳答案
注册成功后,当前用户可以通过[PFUser currentUser]
访问,所以...
- (IBAction)signup_name:(id)sender{
PFUser *user = [PFUser currentUser];
应该可以。
关于ios - 使用 ios 更新用户配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22992490/