Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Julian Bucci
Julian Bucci
3,656 Points

Query return NULL PFObject (NOT THE USUAL QUESTION REGARDING NULL Queries)

I am creating an app that must allow users to comment on a photo.

To do so, I must pass a PFObject called "goal" through multiple viewcontrollers using an NSNotification. In doing this, I have been able to 1) connect the comment to the appropriate photo and 2) **I was told that this would allow me to query all the comments associated with each photo.

this is my notification:

-(void)commentGoal:(id)sender {

NSLog(@"you clicked on button %@", sender);
[[NSNotificationCenter defaultCenter]
 postNotificationName:@"CommentPressed"
 object:self];    

}

and this is where I have received my notification:

-(void)receivedNotification:(NSNotification *)notification { DraggableView *view = notification.object; PFObject *goal = view.goal;

CommentsViewController *commentsVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"Comments"];
[self.navigationController pushViewController:commentsVC animated:YES];

//allows comments to access PFObject "goal"
CommentsViewController *commentOnGoal = notification.object;
commentsVC.goal = commentOnGoal.goal;

//to associate comments in cells with correct card
QueryViewController *commentInCell = notification.object;
commentsVC.goal = commentInCell.goal;

commentInCell = [[QueryViewController alloc] init];
((QueryViewController *)commentInCell).goal = goal;


//this line of code is causing two errors:
// 1) Property 'goal' not found on object of type ID
// 2) Property 'goal' not found on object of type "QueryViewController"
QueryViewController.goal = notification.object.goal;

}

I left comments to show you guys where my error is. The specific line causing an error is the last line of the receivedNotification method: QueryViewController.goal = notification.object.goal;

How can I solve this issue? I believe that once this issue is resolved, I'll be able to run my app and my query will not return null when executing this line:

[commentQuery whereKey:@"ActivityGoalKey" equalTo:self.goal];

I know this is a long question, so thank you in advance for taking the time to read it. If you need further information please let me know.