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

alex molineaux
alex molineaux
4,367 Points

We are working on an app to download videos of the Treehouse Show, which are listed in a table view. The user will tap o

Hi

Really got stuck on this little code challenge. Here is my answer which is obviously wrong. Why oh Why don't they post an answerโ€ฆ?

I would really appreciate any help.

// This code is excerpted from the didSelectRowAtIndexPath method of a view controller

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

// Add your code below to mark rows as selected or not! if (cell.accessoryType == UITableViewCellAccessoryNone) { cell.accessoryType = UITableViewCellAccessorynone;

} else { cell.accessoryType = UITableViewCellAccessoryCheckMark;

}

1 Answer

Stone Preston
Stone Preston
42,016 Points

you have the right idea

this code is run when the user taps a cell. first you check to see if the cell doesnt have a checkmark. if it doesnt, add a checkmark. else (it already has a check) remove the check mark.

// This code is excerpted from the didSelectRowAtIndexPath method of a view controller

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

// Add your code below to mark rows as selected or not!

//check and see if it DOESNT have a checkmark when its tapped
if (cell.accessoryType == UITableViewCellAccessoryNone) {
        //not checked yet, so we need to add a check to the cell
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
       //already checked, remove the checkmark
       cell.accessoryType = UITableViewCellAccessoryNone;
}
alex molineaux
alex molineaux
4,367 Points

Thanks so much for the answer I learned a lot from your comments was well. I really appreciate it.