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
bradley
4,267 PointsBuild a Self-Destructing Message iPhone App code challenge 1 of 1
question :Create a list of shows to download by adding the code below to mark rows as selected or not using 'UITableViewCellAccessoryCheckmark' and 'UITableViewCellAccessoryNone'.
can someone help, I'm stuck.... here is my code, not sure what i'm doing wrong
// This code is excerpted from the didSelectRowAtIndexPath method of a view controller
Im adding NSMutableArray *shows = [NSMutableArray arrayWithCapacity:1];
// Add your code below to make this work! if (cell.accessoryType == UITableViewCellAccessoryNone) { cell.accessoryType = UITableViewCellAccessoryCheckmark; [shows addObject:[objectAtIndex:indexPath.row]];
} else {if (cell.accessoryType == UITableViewCellAccessoryCheckmark) { cell.accessoryType = UITableViewCellAccessoryNone; }
}
8 Answers
jschlansky
7,229 PointsThe question was confusing on this one. It technically only asks you to "add the code below to mark rows", and doesn't require you to actually add anything to a list. You are thinking the right way, though.
Simply removing the "[shows addObject:[objectAtIndex:indexPath.row]];" line should allow you to move on.
Felix Guerrero
3,813 PointsI've found some confusing this task. The author should change the question.
Ben Jakuben
Treehouse TeacherSorry everyone! I just started a round of new code challenges and updates and will update this one.
bradley
4,267 PointsTaylor, thanks for your help, i originally had it that way but it still does not work. here is my updated code, however i get a bummer ! Bummer! Don't forget to set the 'cell' variable's 'accessoryType' property! after submitting the code below
// This code is excerpted from the didSelectRowAtIndexPath method of a view controller
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSMutableArray *shows = [NSMutableArray arrayWithCapacity:1];
// Add your code below to make this work!
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
Ben Jakuben
Treehouse TeacherIn this case you just have an errant left curly brace { between "else" and "if" that shouldn't be there. :)
bradley
4,267 Pointshi Ben, thanks for your reply, its still not working for me.... here is my updated code
// This code is excerpted from the didSelectRowAtIndexPath method of a view controller
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// Add your code below to make this work!
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else if (cell.accessoryType == UITableViewCellAccessoryCheckmark){
cell.accessoryType = UITableViewCellAccessoryNone;
}
Ben Jakuben
Treehouse TeacherIt took me a while to figure this last one out. The last part should just be an else condition, not "else if" with the check for the checkmark. I'm not sure why that's throwing off the code challenge engine as it's acceptable code. I'll take a look at it.
bradley
4,267 PointsBen, got it thanks...
Jared Galanis
8,382 PointsI've tried writing the above (while changing else if to else) and it did not work for me. here is the code:
// This code is excerpted from the didSelectRowAtIndexPath method of a view controller
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// Add your code below to make this work!
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else (cell.accessoryType == UITableViewCellAccessoryCheckmark){
cell.accessoryType = UITableViewCellAccessoryNone;
}
Jared Galanis
8,382 PointsNevermind, I realized the else statement does not require:
(cell.accessoryType == UITableViewCellAccessoryCheckmark)
bradley
4,267 Pointsyes .. i think Ben will update...
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherI think I can word that better. Thanks for pointing it out!