我想在我的PFUser子类中添加一个指针字段,由PFUser子类管理。理想情况下,指针对象将在PFUser子类上自动可用 - 在保存和提取用户时保存并获取。
对于任何其他PFObject子类,我只需添加一个Dynamic属性,并确保在查询时使用includeKey。
但是,对于PFUser子类,我实际上从不查询。如何强制指针对象获取?
答案 0 :(得分:4)
在objective-c中,这是一个简单的两步过程,即使有子类:
使用fetchIfNeededInBackground
在本地填充指针对象
PFObject *yourPointerObject = [[PFUser currentUser] objectForKey"pointerKey"];
[yourPointerObject fetchIfNeededInBackground];
答案 1 :(得分:0)
参考PFUser
PFUser *userObjRef = [PFUser currentUser];
获取对象参考
NSString *columnIdStr = [userObjRef objectForKey:@"column_id_Ref"];
获取与column_id相关的基础对象
[[PFUser currentUser] refreshInBackgroundWithBlock:^(PFObject *object, NSError *error) {
[[object objectForKey:@"column_id_Ref"] fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (!error){
self.nameLabel.text = [object objectForKey:@"obj_name_ref"];
}
}];
}];
[[PFUser currentUser] fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {
[[object objectForKey:@"column_id_Ref"] fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (!error){
self.nameLabel.text = [object objectForKey:@"obj_name_ref"];
}
}];
}];
希望它可以帮助你......!