【发布时间】: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