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
obey me
1,135 PointsComment Button
please if you have any ideas help me
1 Answer
Kai Aldag
Courses Plus Student 13,560 Pointsand found it, in PAPPhotoDetailViewController check out this line of code,
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSString *trimmedComment = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (trimmedComment.length != 0 && [self.photo objectForKey:kPAPPhotoUserKey]) {
PFObject *comment = [PFObject objectWithClassName:kPAPActivityClassKey];
[comment setValue:trimmedComment forKey:kPAPActivityContentKey]; // Set comment text
[comment setValue:[self.photo objectForKey:kPAPPhotoUserKey] forKey:kPAPActivityToUserKey]; // Set toUser
[comment setValue:[PFUser currentUser] forKey:kPAPActivityFromUserKey]; // Set fromUser
[comment setValue:kPAPActivityTypeComment forKey:kPAPActivityTypeKey];
[comment setValue:self.photo forKey:kPAPActivityPhotoKey];
PFACL *ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[ACL setPublicReadAccess:YES];
comment.ACL = ACL;
[[PAPCache sharedCache] incrementCommentCountForPhoto:self.photo];
// Show HUD view
[MBProgressHUD showHUDAddedTo:self.view.superview animated:YES];
// If more than 5 seconds pass since we post a comment, stop waiting for the server to respond
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(handleCommentTimeout:) userInfo:[NSDictionary dictionaryWithObject:comment forKey:@"comment"] repeats:NO];
[comment saveEventually:^(BOOL succeeded, NSError *error) {
so here they check length and trim it and such, set all the values for the comment (notice that it's of the class "kPAPActivityClassKey") then we set its caching (i don't know how much you know about that but it's an amazing thing to know for something like this) and save it. so pick around on how they do it because it might help you out.
Good to see you again, Kai
Kai Aldag
Courses Plus Student 13,560 PointsI don't have it in my app but I'll tell you what. I'm working on a social music app that needs to be kick-ass for my presentation on it by the 3rd, I've been slacking a bit on it to answer forum questions but I'll incorporate comments into the app then show you how I did it and how you can add it. how does that sound?
Kai Aldag
Courses Plus Student 13,560 PointsKai Aldag
Courses Plus Student 13,560 Pointsreading up on it now, here is the first part you should check out.