[PFUser currentUser]
ユーザー ID をキーの 1 つとして、写真を PFObject として Parse に保存しています。
その 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];
NSLoguser
を取得すると、 のみが取得されます<PFUser:nOpK5splEX:(null)> { }
が、 NSLog[PFUser currentUser]
を取得すると<PFUser:nOpK5splEX:(null)> { displayName = "XXX"; facebookId = XXX; profilePicture = "<PFFile: XXX>"; username = XXX;}
... 明らかに、PFUser が正しく設定されていません。
ユーザーフィールドなどをリンクするためにデータベースで何かをする必要がありますか?