【问题标题】:Retrieve custom user's profile image检索自定义用户的个人资料图像
【发布时间】:2015-09-07 06:04:30
【问题描述】:

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

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"];

【问题讨论】:

  • 在 tableview 之外尝试一次并检查是否出现相同的错误
  • 代码 [comment objectForKey:@"author"] 返回的值看起来像 NSString,因为您正在设置 cell.titleLabel.text = [comment objectForKey:@"author"];稍后您将设置 PFUser *currentUses = [comment objectForKey:@"author"] 这是 NSString 而不是 PFUser。

标签: ios parse-platform pfuser


【解决方案1】:

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

【讨论】:

  • 你是对的,它是一个字符串。我试图让用户了解字符串的详细信息。当我使用 [PFUser currentuser] 时,所有照片都是登录用户的照片,而不是评论者的照片!
  • 您可以使用用户名PFQuery *query = [PFUser query]; [查询 whereKey:@"username" equalTo:@"actualUsername"]; PFUser *user = (PFUser *)[query getFirstObject];
  • 成功了!有效!有效!非常感谢!
猜你喜欢
  • 2011-06-04
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
  • 2019-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多