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

The checkmarks still appear on the Friends screen and not on the EditFriends screen. Any help would be appreciated!

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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // get current user based on indexPath and set the cell's textLabel
    PFUser *user = [self.friends objectAtIndex:indexPath.row];
    cell.textLabel.text = user.username;

    if ([self isFriend:user]) {
        // found a friend - add checkmark
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        // not a friend - clear checkmark
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    return cell;
}

# pragma mark - Helper Methods

// is called each time a cell is loaded in a view
// return true if a cell is marked as a friend
// Parse creates an objectId for each object stored - unique to each object
-(BOOL)isFriend:(PFUser *)user {

    for (PFUser *friend in self.friends) {
        if ([friend.objectId isEqualToString:user.objectId]) {
            // found a friend
            return YES;
        }
    }
    // not a friend
    return NO;
}

1 Answer

Tingting Gu
Tingting Gu
10,760 Points

Have you used prepareForSegue method in FriendsViewController correctly?

Your posted code in EditFriendsViewController seems fine.