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
Gregg Mojica
11,506 PointsAdd Number in Parse.com
Hi Guys,
So Stone Preston was kind enough to help me with my previous question.
I'm using a tableview.
I now need to be able to add 1 to a column in parse.com called "likedKey". I then need this number to be able to save and reload into a UILabel. So far, I have a UILabel set up and in IBAction setup to handle this. I'm just not sure how to add that number (and save it to the appropriate cell in that row in Parse).
Any ideas?
Thanks!!!!
1 Answer
Camilo Castro
Courses Plus Student 2,549 PointsIn Parse you can use increment method for adding numbers.
PFObject * post = [PFObject objectWithoutDataWithClassName:@"Post" objectId:@"<Post Object ID>"];
[post incrementKey:@"commentCount"];
// Save Post in DB
[post saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
// Get the Lastest Comment Count
[post refreshInBackgroundWithBlock:^(PFObject *object, NSError *error) {
NSLog(@"Comment Count %@", object[@"commentCount"]);
}];
}];
Gregg Mojica
11,506 PointsGregg Mojica
11,506 PointsHi Camilo, Thanks, this is working...however, I don't want to be restricted to a single objectId. Is there any way I can use this for all objectIds?
Camilo Castro
Courses Plus Student 2,549 PointsCamilo Castro
Courses Plus Student 2,549 PointsYou need to create a new Column that will store the "Like Count" in DB.
Here's the API Doc for Increment Method
http://www.parse.com/docs/ios/api/Classes/PFObject.html#//api/name/incrementKey:
When you Select a Cell in didSelectRowAtIndexPath method
You Increment the counter and Update the Datasource for Cell TextLabel.
Then you use for showing the new value
[tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationAutomatic];
Hope it helps :)
Gregg Mojica
11,506 PointsGregg Mojica
11,506 PointsOk, so I have that column called LikedKey. I really want to thank you for all your help so far. :)
I'm not sure if you say this (because I updated my question), but how do I load all object ides, not just the one I hard coded in?
Camilo Castro
Courses Plus Student 2,549 PointsCamilo Castro
Courses Plus Student 2,549 PointsMaybe this is what you are looking for