检索自定义用户的个人资料图片

时间:2015-09-07 06:04:31

标签: ios parse-platform pfuser

我在为发表评论的用户检索个人资料图片时遇到问题。这是我正在使用的代码

HTKSampleTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"commentReuseID"];
PFObject *comment = [comments objectAtIndex:indexPath.row];
cell.commentLabel.text = [comment objectForKey:@"text"];

NSDateFormatter* formatter = [NSDateFormatter new];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateStyle:NSDateFormatterShortStyle];
NSString* uploaded = [formatter stringFromDate:comment.createdAt];

cell.timeLabel.text = uploaded;

cell.titleLabel.text = [comment objectForKey:@"author"];


[cell.samImageView loadInBackground];


PFUser *currentUses = [comment objectForKey:@"author"];

[currentUses fetchIfNeededInBackgroundWithBlock:^(PFObject *object, NSError *error) {
   NSString *userphoto = [object objectForKey:@"image"];
    NSLog(@"%@", userphoto);

}];

当我使用NSLog时,currentUses返回用户的用户名,因为我将其帖子类保存为“作者”。

这是我得到的错误:

  

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [__ NSCFString fetchIfNeededInBackgroundWithBlock:]:无法识别的选择器发送到实例0x15f4d670'

上面的查询确实有:[query includeKey:@“user”];

1 个答案:

答案 0 :(得分:2)

[comment objectForKey:@“author”]返回的值是NSString而不是PFUser。所以你得到了例外。