farhan
farhan

Reputation: 3

Having trouble passing PFUser as a PFObject

so in my app, I want to implement user profiles by clicking on a UIButton, I have all the functionality done.

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.

heres my code in -(void)didSelectRow

PFObject *object = [self.objects objectAtIndex:selectedRow];
PFUser *user = [object objectForKey:@"userTookPhoto"];

self.userInfo = user;

self.userInfo is a property PFUser in the .h file

Then in my PrepareSegue I have this :

else if ([segue.identifier isEqualToString:@"homeToProfile2"])
    {

        transfer.userInformationObject = self.userInfo;
    }

I run the app, and i tap on the button to push segue and the app crashes saying that self.userInfo is 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.

Upvotes: 0

Views: 325

Answers (1)

jsetting32
jsetting32

Reputation: 1632

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...

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"]);
    }
}];

The log statement will return the PFUser object.

Heres a link to an explanation of your problem on Parse Blog

Upvotes: 1

Related Questions