在文档https://www.parse.com/docs/ios/guide#relations-using-pointers中 它说,在提供的示例中,您可以找到创建游戏的用户
// say we have a Game object
PFObject *game = ...
// getting the user who created the Game
PFUser *createdBy = [game objectForKey:@"createdBy"];
但是当我使用确切的语法时,因为我想在我的" user"中填充指针。柱
PFUser *user = [PFUser currentUser];
NSString *username = user.username;
// Inside my queryForTable method so PFObject is returned in
// tableView:cellForRowAtIndexPath:object
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"fromUser = %@", user];
PFQuery *query = [PFQuery queryWithClassName:@"Activities" predicate:predicate];
// Inside tableView:cellForRowAtIndexPath:object
PFUser *createdBy = [object objectForKey:@"user"];
NSLog(@"User to user ---%@", createdBy);
但我得到的只是
User to user ---<PFUser: 0x7ff9024da860, objectId: aOisP569e3, localId: (null)> {
// Nothing here
}
如果我理解正确,我是否也应该在我的用户对象中找回用户名,电子邮件等?
---更新1 ---
查看解析提供的Anypic应用程序它应该返回类似这样的内容
<PFUser: 0x7f7ff9fafc00, objectId: LfADtx1K2J, localId: (null)> {
// Stuff appears here
displayName = "poopiu";
facebookId = 130941340571204;
profilePictureMedium = "<PFFile: 0x7f7ff9faf500>";
profilePictureSmall = "<PFFile: 0x7f7ff9faf7f0>";
username = I34MBM3WYSB5tjWIIvUvhH5fq;
}
但我的是空的,即使我有一个名为username的列未定义,所以我应该在我的PFUser对象中找到它
- 更新2 -
这是我从日志记录对象中得到的内容......
NSLog(@"Object---%@", object);
<Activities: 0x7fbbebf42d20, objectId: rDwYI5Inuk, localId: (null)> {
user = "<PFUser: 0x7fbbee1367e0, objectId: SFL0kVZ17x>";
status = 0;
>
答案 0 :(得分:2)
在实例化query
后添加以下方法调用。
[query includeKey: "user"];
默认情况下,查询不会通过查询的直接对象获取信息。
答案 1 :(得分:0)
您确定user
不是nil
吗?根据{{3}},您必须登录currentUser
才能返回用户对象。
答案 2 :(得分:0)
[createdBy fetch];
NSLog(@"User to user ---%@", createdBy);
试试希望这会有所帮助