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

iOS

obey me
obey me
1,135 Points

Like & Comment in UITableViewFooter

UIButton button = (UIButton *)[cell viewWithTag:100]; [button addTarget:self action:@selector(MethodName:) forControlEvents:UIControlEventTouchUpInside]; -(void)yourButtonClicked:(UIButton)sender { if (sender.tag == 0) { // i dont know what to here } }

1 Answer

Hello,

are you liking a PFObject, if so I would recommend you make a relation where a post has an association to all the users liking it. so, in you selector method I would add something like,

PFRelation *like= [/*some post object*/ relationForKey:@"like"];
[like addObject:[PFUser currentUser]];
[like saveInBackground];

something like that. check out anypic from parse, it has a great example on how to do this.

Best, Kai

obey me
obey me
1,135 Points

what about a comment button do you have any sample code

Hmmm, a comment should have a user who posted it along with some string containing the comment message. so what you could do is something like,

PFRelation *comment= [/*some post object*/ relationForKey:@"comment"];


PFObject *postMessage = [[PFObject alloc]initWithClassName:@"comment"];
 [postMessage addObject:/*comment text here*/ forKey:@"commentContent"];
[postMessage addObject:[PFUser currentUser] forKey: @"postedBy"];

[comment addObject:postMessage];
[comment saveInBackground];

this is something off the top of my head but it should work, once again, parse has a great example called anypic that should help alot.

Best, Kai

obey me
obey me
1,135 Points

so the logic behind the comment button is basically when the button is tapped it shows a small uiview or uitableviewcell then we have a textfield to input the comments then we use a uilabel to display under right .. if you can please show me a sample code i am trying to get this part for over a month now

OK i see, so when we hit a button we'll trigger an action to display the textField for input then when they hit post we'll use the code above. to do this, when the button is tapped we'll do something like this,

//make a public textField called "commentField" because you'll need its text for the code above, you can make it public then just use the .text to get its value or you could do something like KVO but public is alot easier
-(void)showCommentField{
    commentField = [[UITextField alloc]initWithFrame:CGRectMake(/*enter where you want it*/)

    //you might need to move other items out of the way or expand the cell if you're using one, let me know if you need that because in my project i've got the code for it

    //add to view, if it's a cell add it there by making the cell public
    [self.view addSubview:commentField]
}

let me know if you have thing that need to be moved around because I can help you out with that part too.

obey me
obey me
1,135 Points

but which one is better to use the UIView or UItableview

If you're showing multiple posts i'd use a tableView (i personally use collectionViews for more customization) and a UIView for something like a single post.

Did this do it?

obey me
obey me
1,135 Points

yeah i text u on twitter Kai Aldag