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


patrick tagliaferro
patrick tagliaferro
5,399 Points

Only one check mark at a time

I have the checking and unchecking working in my app but I wanted to change it so that you can have only one check box (selecting another will deselect and remove data when doing so). My thought was check to see if agent, if so do nothing, if not remove current agent check mark/data/ then add to checkbox/data to current selection but getting an error since I am using "for" wrong. Not sure if that would even work

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

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    PFObject *agent = [self.allAgents objectAtIndex:indexPath.row];
    PFRelation *agentRelation = [self.currentUser relationForKey:@"agentRelation"];

    if ([self isAgent:agent]) {

        for ([self isAgent:agent]){
            //Remove Check
            cell.accessoryType = UITableViewCellAccessoryNone;

            //Reomve from Agent array
            for (PFObject *myAgent in self.agents){
                if ([myAgent.objectId isEqualToString:agent.objectId]) {
                    [self.agents removeObject:agent];

            //Remove from Backend
            [agentRelation removeObject:agent];


        cell.accessoryType = UITableViewCellAccessoryCheckmark;
        [self.agents addObject:agent];
        [agentRelation addObject:agent];

    [self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            NSLog(@"Error: %@", error);