检索自定义用户的配置文件图像
我在为留言评论的用户检索配置文件图像时遇到问题。下面是我使用检索自定义用户的配置文件图像
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为I级保存我的职位,如返回用户的用户名“作者”。
这是错误我得到:
终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因是: ' - [__ NSCFString fetchIfNeededInBackgroundWithBlock:]:无法识别的选择发送到实例0x15f4d670'
上面的查询确实有:[query includeKey:@“user”];
[comment objectForKey:@“author”]返回的值是NSString不是PFUser。所以你得到了例外。
你说得对,它是一个字符串。我试图让用户了解字符串的细节。当我使用[PFUser currentuser]时,所有照片都是用户登录的,而不是评论者的照片! – HalesEnchanted
您可以使用用户名PFQuery * query = [PFUser query]获取PFUser; [查询whereKey:@“username”equalTo:@“actualUsername”]; PFUser * user =(PFUser *)[query getFirstObject]; –
它的工作!有效!有效!非常感谢! – HalesEnchanted
在tableview之外尝试一次,并检查是否得到相同的错误 –
代码返回的值[comment objectForKey:@“author”]看起来像NSString,因为您正在设置cell.titleLabel.text = [comment objectForKey: @“作者”];稍后,您将设置PFUser * currentUses = [comment objectForKey:@“author”],它是NSString不是PFUser。 –