无法将 PFUser 作为 PFObject 传递 [英] Having trouble passing PFUser as a PFObject
问题描述
所以在我的应用程序中,我想通过单击 UIButton
来实现用户配置文件,我已经完成了所有功能.
so in my app, I want to implement user profiles by clicking on a UIButton
, I have all the functionality done.
我首先添加了在选择 indexPath.section
时显示用户信息的功能,所以我想通过一个按钮来做同样的事情.
I first added the functionality when the indexPath.section
is selected the user information is shown, so then I wanted to do the same thing through a button.
这是我在 -(void)didSelectRow
PFObject *object = [self.objects objectAtIndex:selectedRow];
PFUser *user = [object objectForKey:@"userTookPhoto"];
self.userInfo = user;
self.userInfo 是 .h
文件中的一个属性 PFUser
self.userInfo is a property PFUser
in the .h
file
然后在我的 PrepareSegue
中我有这个:
Then in my PrepareSegue
I have this :
else if ([segue.identifier isEqualToString:@"homeToProfile2"])
{
transfer.userInformationObject = self.userInfo;
}
我运行应用程序,然后点击按钮以推动 segue,应用程序崩溃,说 self.userInfo
为 NULL.
I run the app, and i tap on the button to push segue and the app crashes saying that self.userInfo
is NULL.
当我在 didSelectRow
中 NSlog
它时,它的信息与所有用户详细信息都是正确的,当我在 prepareSegue
中 NSlog
它时它崩溃了,因为它说它是 NULL
.
When I NSlog
it in didSelectRow
, it has the information correct with all the user details,
when I NSlog
it in the prepareSegue
it crashes as it says it is NULL
.
推荐答案
如果要访问 PFObject
中的 PFObjects
对象,则需要在 PFQuery 中包含includeKey:
方法并传入PFObject
所在的字段...
If you want to access PFObjects
objects within a PFObject
, you need to include within your PFQuery the includeKey:
method and pass in the field that the PFObject
is...
因此,如果您访问 PFObject
中的 PFUser
对象,其类名为Message",则您可以像这样创建查询...
So if your accessing a PFUser
object within a PFObject
whose classname is 'Message', you create the query like so...
PFQuery *query = [PFQuery queryWithClassname:@"Message"];
[query whereKey:@"toUser" equalTo:[PFUser currentUser]];
[query includeKey:@"toUser"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
for (PFObject *obj in objects) {
NSLog(@"%@", [obj objectForKey:@"toUser"]);
}
}];
日志语句将返回 PFUser 对象.
The log statement will return the PFUser object.
这篇关于无法将 PFUser 作为 PFObject 传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!