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 trialalex molineaux
4,367 PointsWe 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
42,016 Pointsyou 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
4,367 Pointsalex molineaux
4,367 PointsThanks so much for the answer I learned a lot from your comments was well. I really appreciate it.