在获取其值之前解析所需的调用

rjs*_*o77 3 objective-c ios parse-platform

我是目标c的新手,我使用parse.com作为社交媒体应用程序的数据库.我想要做的是从POST表中获取用户的帖子.我正在使用指针从我的USER表中获取用户名,这很好,正如您将在下面发布的代码中看到的那样,但是当我在将UILabel分配给用户的帖子之前使用fetchifneeded时,我仍然会收到此错误"密钥"故事"没有数据.在获取其值之前调用fetchIfNeeded." 我感谢任何帮助,并感谢你的进步,如果我没有让自己清楚,不管怎样,我会更乐意扩展任何事情.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
    if (indexPath.section == self.objects.count) {
        UITableViewCell *cell = [self tableView:tableView cellForNextPageAtIndexPath:indexPath];
        return cell;
    }

    static NSString *CellIdentifier = @"StoryCell";

    NinetiesCell *cell = (NinetiesCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    //for the post of the user
    PFObject *user = object[@"User"];
    [user fetchIfNeeded]; 
    //get username from pointer
    cell.userName.text = user[@"username"];

    PFObject *story = [object objectForKey:@"Story"];
    [story fetchIfNeeded];
    cell.story.text = [object objectForKey:@"Story"];

    // Configure the cell

    NSDate *updated = [object createdAt];

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

    [dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];

    cell.dateLabel.text = [NSString stringWithFormat:@"%@", [dateFormat stringFromDate:updated]];

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

Tim*_*ers 5

在您的情况下,更好的选择是修改您的原始查询以包括"用户"和"故事"列,例如

[query includeKey:@"User"];
[query includeKey:@"Story"];
Run Code Online (Sandbox Code Playgroud)

然后,当您引用这些列时,tableView:cellForRowAtIndexPath:它们将已填充,无需调用fetchIfNeeded.