我将一张照片作为 PFObject 保存到 Parse,其中[PFUser currentUser]
用户 ID 作为其键之一。
我想在表格视图中显示照片以及来自该 PFUser 的详细信息。但是当我尝试获取用户 - PFUser *user = [self.photo objectForKey:@"user"];
- 然后尝试访问用户的显示名称时,我得到以下异常:
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"];
,一切正常。
我在某处错过了一步吗?谢谢!
这是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 设置键的地方:
PFObject *photo = [PFObject objectWithClassName:@"Photo"];
[photo setObject:[PFUser currentUser] forKey:@"user"];
[photo setObject:self.photoFile forKey:@"image"];
[photo setObject:[nameField text] forKey:@"itemCaption"];
这里是我为 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 没有正确设置。
我应该在数据库中做些什么来链接用户字段或类似的东西吗?