我正在关注Parse.com上的教程,但我似乎并没有让它正常工作。这是我的问题。
我有一个名为Questions
的类和一个名为_User
的类,类型为PFUser(类名旁边有一个图片图标)。用户通过FB登录并注册为_User
。我可以在_User
课程中看到自己。
我提出了一个问题,我在名为Question
的{{1}}类中有一个字段,该字段是问题的所有者。这是在通过ios应用程序保存新问题时设置的,如下所示:
qOwner
我可以在QuestionCard[@"qOwner"] = [PFUser currentUser];
中看到自己的objectId
为_User
列中的值,位于当前问题的行中。
问题是我无法检索应用内的值。如果我放在下面的正确位置:
qOwner
正在印刷以下内容:
1)
PFQuery *query = [PFQuery queryWithClassName:@"Questions"];
[query addAscendingOrder:@"createdAt"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"@@@ : Successfully retrieved %lu questions ", (unsigned long)objects.count);
// Do something with the found objects
NSLog(@"%@",objects);
// fetched data are PFObjects
// we need to convert that into a YesOrNo object
// and then add it to _cards array
for (PFObject *object in objects) {
NSLog(@"currentUser : %@",[PFUser currentUser]);
PFUser *qOwnerUser = [object objectForKey:@"qOwner"];
NSLog(@"Question Made by : %@",qOwnerUser);
}
.....
2)
@@@ : Successfully retrieved 1 cards
3)
(
"<Questions: 0x17011f5c0, objectId: zZWGsfciEU, localId: (null)> {\n CardId = 999;\n qOwner = \"<PFUser: 0x17037e000, objectId: LtdxP5K0n6>\";\n type = 0;\n }"
)
4)
currentUser : <PFUser: 0x174375e40, objectId: LtdxP5K0n6, localId: (null)> {
facebookId = 10153480462518901;
thumbnail = "<PFFile: 0x174479a80>";
username = UYRRmfbXDHqr1Ws4VwJcAy2wx;
}
1-2-3似乎正确,我可以看到指针关系。但为什么在4 Question Made by : <PFUser: 0x17037e000, objectId: LtdxP5K0n6, localId: (null)> {
}
里面我什么都没看到?我希望看到与3中相同的用户详细信息。
我错过了什么吗?
答案 0 :(得分:4)
Parse在查询中默认不提取指针值。您必须告诉查询使用includeKey:
包含指针数据。这样做:
PFQuery *query = [PFQuery queryWithClassName:@"Questions"];
[query addAscendingOrder:@"createdAt"];
[query includeKey:@"qOwner"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
...
}];