本文介绍了Parse.com从相关的PFObject获取PFUser的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将照片保存为PFObject,以[PFUser currentUser]用户ID作为其键之一.

I'm saving a photo to Parse as a PFObject with the [PFUser currentUser] user ID as one of its keys.

我想在表格视图中显示该照片以及该PFUser的详细信息.但是,当我尝试获取用户-PFUser *user = [self.photo objectForKey:@"user"];-然后尝试访问用户的显示名称时,出现以下异常:

I want to display the photo in a table view alongside details from that PFUser. But when I try to get the user - PFUser *user = [self.photo objectForKey:@"user"]; - and then try to access the user's display name, I get the following exception:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Key "profilePicture" has no data.  Call fetchIfNeeded before getting 
its value.'

但是,调用fetchIfNeeded会使表崩溃,并且AnyPic教程完全执行了我要尝试执行的操作,而没有使用fetchIfNeeded. AnyPic只需调用PFUser *user = [self.photo objectForKey:@"user"];,一切正常.

Calling fetchIfNeeded crashes the table, though, and the AnyPic tutorial does exactly what I'm trying to do without using fetchIfNeeded. AnyPic just calls PFUser *user = [self.photo objectForKey:@"user"]; and everything works.

我在某处错过了一步吗?谢谢!

Am I missing a step somewhere? Thanks!

这是cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
    static NSString *CellIdentifier = @"Cell";

    PhotoCellTest *cell = (PhotoCellTest *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[PhotoCellTest alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier descriptionText:nil userNameText:nil captionText:nil];
    }

    photo = object;
    PFUser *user = [self.photo objectForKey:@"user"];
    PFFile *profilePictureSmall = [user objectForKey:@"profilePicture"];
    cell.profilePicPlaceholder.file = profilePictureSmall;



    return cell;
}

修改

在这里设置PFObject的键:

Here's where I set the keys for the PFObject:

PFObject *photo = [PFObject objectWithClassName:@"Photo"];
    [photo setObject:[PFUser currentUser] forKey:@"user"];
    [photo setObject:self.photoFile forKey:@"image"];
    [photo setObject:[nameField text] forKey:@"itemCaption"];

这是我为PFUser设置密钥的地方:

And here's where I set the keys for the PFUser:

PFFile *profilePic = [PFFile fileWithData:data];
    [[PFUser currentUser] setObject:profilePic forKey:@"profilePicture"];
    [[PFUser currentUser] saveInBackground];

当我的NSLog user时,我只会得到<PFUser:nOpK5splEX:(null)> { },但是当我的NSLog [PFUser currentUser]时,我将会得到<PFUser:nOpK5splEX:(null)> { displayName = "XXX"; facebookId = XXX; profilePicture = "<PFFile: XXX>"; username = XXX;} ...因此,显然PFUser的设置不正确.

When I NSLog user, I only get <PFUser:nOpK5splEX:(null)> { }, but when I NSLog [PFUser currentUser], I get <PFUser:nOpK5splEX:(null)> { displayName = "XXX"; facebookId = XXX; profilePicture = "<PFFile: XXX>"; username = XXX;}... So obviously the PFUser isn't getting set correctly.

我应该在数据库中做一些事情来链接用户字段或类似的东西吗?

Am I supposed to do something in the database to link the user fields or something like that?

推荐答案

知道了-我在PFQuery中没有使用includeKey.

Got it figured out - I wasn't using an includeKey in the PFQuery.

这篇关于Parse.com从相关的PFObject获取PFUser的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 09:55