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 Build a Self-Destructing Message iPhone App Relating Users in Parse.com Adding Friends by Tapping on a Table View Cell

Brian Rudolph
Brian Rudolph
9,340 Points

TableView not deselecting properly

When I select a friend in the friend list, the row stays highlighted (gray) and no checkmark appears; however, when I select someone else in the friend list, the previous row gets the checkmark and the current row experiences the same thing (i.e. the second row stays highlighted and won't get its checkmark until I deselect it.

Here's the relevant code:

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.accessoryType = UITableViewCellAccessoryCheckmark;

    PFRelation *friendsRelation = [self.currentUser relationForKey:@"friendsRelation"];
    PFUser *user = [self.allUsers objectAtIndex:indexPath.row];
    [friendsRelation addObject:user];
    [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);

4 Answers

Brian Rudolph
Brian Rudolph
9,340 Points

Oh, sorry about the repost then. I'll let you know if we get a response here.

I am having this exact same problem and created a forum post a little more than an hour before yours. I was thinking it could be something to do with the IOS/Xcode version differences but don't know for sure. Hopefully someone can help us out. https://teamtreehouse.com/forum/friends-do-not-add-or-get-removed-when-clicked

Not a problem. The more this question is out there, the more likely we get it figured out :)

-(void)tableView:(UITableView *)tableView did ->De <- "remove" ->S<- Make the" s capital" SelectRowAtIndexPath:(NSIndexPath *)indexPath {

[self.tableView deselectRowAtIndexPath:indexPath animated:NO];

You accidentally took the wrong method from the autocomplete. It must be didSelect :-)