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! While you're at it, check out some resources Treehouse students have shared here.
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
Julian Bucci
3,656 PointsPassing PFObject to multiple view controllers using NSNotification
Hey guys! I have a Query that is passing a PFObject called "sampleGoal".
The Query is created in my QueryViewController (this is a PFQueryTableViewController) and I am passing the PFObject "sampleGoal" from another viewController using an NSNotification.
-(PFQuery *)queryForTable {
PFQuery *commentQuery = [PFQuery queryWithClassName:self.parseClassName];
[commentQuery whereKey:@"ActivityGoalKey" equalTo:self.sampleGoal];
[commentQuery whereKey:@"ActivityTypeKey" equalTo:@"ActivityTypeComment"];
[commentQuery includeKey:@"ActivityFromUserKey"];
[commentQuery orderByAscending:@"createdAt"];
return commentQuery;
}
I was told that my problem is that I am not successfully passing the PFObject "goal" to my QueryViewController. I receive an error telling me that self.goal is null.
How can I successfully pass a PFObject created in one viewController to multiple viewControllers using NSNotification?
Below is my Notification code
created notification in button:
-(void)commentGoal:(id)sender {
NSLog(@"you clicked on button %@", sender);
[[NSNotificationCenter defaultCenter]
postNotificationName:@"CommentPressed"
object:self];
}
received notification here:
-(void)receivedGoalNotification:(NSNotification *)notification {
QueryViewController *queryVC;
queryVC.sampleGoal = notification.object;
}