Parse.com从相关的PFObject获取PFUser
我将[PFUser currentUser]
用户ID作为[PFUser currentUser]
一个关键字保存为Parse。
我想在表格视图中显示照片以及PFUser的详细信息。 但是,当我尝试获取用户 – PFUser *user = [self.photo objectForKey:@"user"];
– 然后尝试访问用户的显示名称,我得到以下exception:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Key "profilePicture" has no data. Call fetchIfNeeded before getting its value.'
然而,调用fetchIfNeeded会使表崩溃,而AnyPic教程正是我所要做的,而不使用fetchIfNeeded。 PFUser *user = [self.photo objectForKey:@"user"];
只是调用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:nOpK5splEX:(null)> { displayName = "XXX"; facebookId = XXX; profilePicture = "<PFFile: XXX>"; username = XXX;}
<PFUser:nOpK5splEX:(null)> { displayName = "XXX"; facebookId = XXX; profilePicture = "<PFFile: XXX>"; username = XXX;}
…所以显然PFUser没有得到正确设置。
我应该在数据库中做些什么来链接用户字段或类似的东西?
知道了 – 我没有在includeKey
中使用includeKey。
后
PFUser *user = [self.photo objectForKey:@"user"];
你应该打电话
[user fetchIfNeeded];