bmu*_*ler 5 iphone ios parse-platform
我将照片保存为Parse作为PFObject,并将[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.'
Run Code Online (Sandbox Code Playgroud)
但是,调用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;
}
Run Code Online (Sandbox Code Playgroud)
编辑
这是我为PFObject设置键的地方:
PFObject *photo = [PFObject objectWithClassName:@"Photo"];
[photo setObject:[PFUser currentUser] forKey:@"user"];
[photo setObject:self.photoFile forKey:@"image"];
[photo setObject:[nameField text] forKey:@"itemCaption"];
Run Code Online (Sandbox Code Playgroud)
这里是我为PFUser设置键的地方:
PFFile *profilePic = [PFFile fileWithData:data];
[[PFUser currentUser] setObject:profilePic forKey:@"profilePicture"];
[[PFUser currentUser] saveInBackground];
Run Code Online (Sandbox Code Playgroud)
当我NSLog时user,我只能得到<PFUser:nOpK5splEX:(null)> { },但是当我在NSLog时[PFUser currentUser],我得到<PFUser:nOpK5splEX:(null)> { displayName = "XXX"; facebookId = XXX; profilePicture = "<PFFile: XXX>"; username = XXX;}......显然PFUser没有正确设置.
我是否应该在数据库中做一些事情来链接用户字段或类似的东西?
| 归档时间: |
|
| 查看次数: |
5323 次 |
| 最近记录: |