
Question:
So what I'm trying to do essentially add a button next on each cell in my UITableView. Each cell in my tableView is being populated from my Event Class on parse where each object is displayed in a new cell.
Once a user hits this button it takes whatever Event object from the Event class they've clicked and possibly adds it to a "property" in the Parse User Class I'll create named "watching".
But how would I do something like this to where they're able to have all of these Events under the User Class "watching property"? Would I have to set up some relation of some sort?
Summary: Basically wanting to have a watch list people are able to watch any of the objects posted by any of the users in the Events Class. These objects that are being watched are added to a property in the User Class so that I can easily create a UITableView pulling the current users watching property list of items and displaying them.
Answer1:I hope I have understood what you want ... If I understand it you need a form of relationship between the object and the CurrentUser viewing it ...
normally to identify the selected cell within a IBAction you can 'use this method:
- (IBAction) button: (id) sender {
NSIndexPath * indexPath = [self.TableView indexPathForSelectedRow];
PFObject SelectedObject * = [self.YOUR_ARRAY objectAtIndex: indexPath.row];
}
This way you've identified which cell the current user has selected .. From this point on, continue with the PFObject to save the data the way you want
The essential thing is to set the goal of PFObject (in this case the selected cell) then continues to set the data to be set according to what you need
Answer2:You could create a field on your PFUser class : @"watching"
Then use this as an array, so whenever the user clicks on something to watch ...
[[PFUser currentUser]addObject:objectToWatch.objectId forKey:@"watching"]; // adds it to the array
[[PFUser currentUser]save];
// something about arrays and parse objects, if you're using operations like "addObject" you should save or you'll get errors.
// the other option is to get an NSMutableArray from the array field, edit that, and reassociate it with the @"watching" key ... whichever you prefer
We now have an array of Id's associated with objects to watch. You could query like so
PFQuery * query = [PFQuery queryWithClassName:@"ObjectsToWatch"];
[query whereKey:@"objectId" containedIn:[PFUser currentUser][@"watching"]];
[query findObjectsInBackground]; // use a block method though
This is only one way to do it, hope it helps