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 Checkmarks When the Table View is Loaded

No checkmarks for me

Hello.

I'm having a problem friend list checkmarks, they are not showing. I've checked everything multiple times, there's no typo and everything is in their places. Xcode Builds app successfully too, no errors.

Compered everything with project file attached to video.

Stone Preston
Stone Preston
42,016 Points

please post your didSelectCellAtIndexPath method and any other code you might think is relevant

4 Answers

I found my bug. EditFriendViewController class was set for both Friend and Edit Friend View Controllers in storyboard. Stupid mistake.

Thank you very much for your help, Stone Preston.

Stone Preston
Stone Preston
42,016 Points

no worries glad you figure it out. Stuff like that happens all the time.

In this part(video) I've added the following:

To EditFriendsViewController.m:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([self isFriend:user]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
}

- (BOOL)isFriend:(PFUser *)user {
    for (PFUser *friend in self.friends) {
        if ([friend.objectId isEqualToString:user.objectId]) {
            return YES;
        }
    }
    return NO;
}

To FriendsViewController:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showEditFriends"]) {
        EditFriendsViewController *viewController = (EditFriendsViewController *)segue.destinationViewController;
        viewController.friends = [NSMutableArray arrayWithArray:self.friends];
    }

}

didSelectCellAtIndexPath in EditFriendsViewController was not edited in this video, but here it is:

[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]);
        }
    }];

All header files are the same as in attached project file under the video.

Segue Friends -> Edit Friends identifier is also set correctly.

Stone Preston
Stone Preston
42,016 Points
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([self isFriend:user]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
}

the first line there

if ([self isFriend:user])

where does that user variable come from? I dont see it defined in the scope of that method.

I'm sorry, I skipped few lines which where added in previous videos.

This is how it looks actually. I tried to save space and posted only the new code. User variable is defined.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    PFUser *user = [self.allUsers objectAtIndex:indexPath.row];
    cell.textLabel.text = user.username;

    if ([self isFriend:user]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}
Stone Preston
Stone Preston
42,016 Points

alright, your code looks pretty good. So you dont see the checkmarks at all? When you tap on a cell do you get a checkmark?