ios - 使用 ios 更新用户配置文件?

标签 ios objective-c parse-platform

我有多个 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 上执行此操作。我有两个文本字段 firstnamelastname:

- (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/

相关文章:

objective-c - 什么时候应该在 IOS 编程中使用 UIViewController?

ios - 如何阻止 TextField 未对齐元素?

ios - 取消 UILocalNotification

ios - 滑动手势返回结合 navigationBarHidden 设置为 YES

ios - 将完成处理程序保存为对象

javascript - 在 Parse 中检索 objectId

parse-platform - Parse.com - 在对象数组中查询

ios - 如何对齐字符串中的 Logo

iOS Watch 应用程序无法安装 - WatchKit 1.0 应用程序无法再在此 watchOS 版本上安装

ios - 如何使 PFQueryTableView 在 UIViewController 中工作