首先,我将当前用户和已连接的书籍提供给该用户(它是指向书籍对象的指针)。然后我想使用getobjectinBackgroundWithId方法找到该书,然后显示书名。当我将getObjectInBackgroundWithId:storeUserID
更改为getObjectInBackgroundWithId:@"f4Dg92xC2"
时,它会完美无缺!
PFUser *currentuser = [PFUser currentUser];
storeUserID = currentuser[@"connectedBook"]; //Store book id in a string
NSLog(@"%@", storeUserID); // what i get <Book:f4Dg92xC2:(null)>
PFQuery *query = [PFQuery queryWithClassName:@"Book"];
[query getObjectInBackgroundWithId:storeUserID block:^(PFObject *books, NSError *error){
PFObject *bookObject = books[@"bookName"];
NSLog(@"bookName:%@", bookObject);
}];
当我运行它时,带有书名的NSLog显示:
错误:错误的特殊键:objectId(代码:102,版本:1.2.20) 2014-09-17 23:28:56.529 MyApp [18977:90b] bookName:(null)
提前多多感谢!!
答案 0 :(得分:1)
您的评论//Store book id in a string
不正确。指针不返回字符串对象id,它返回对象本身。所以你已经拥有它而你不需要拨打getObjectInBackgroundWithId:
。
日志<Book:f4Dg92xC2:(null)>
甚至会告诉您它是Book
实例(不是NSString
实例)。