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 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

The 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.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

I think I can word that better. Thanks for pointing it out!

I've found some confusing this task. The author should change the question.

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Sorry everyone! I just started a round of new code challenges and updates and will update this one.

Taylor, 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
Ben Jakuben
Treehouse Teacher

In this case you just have an errant left curly brace { between "else" and "if" that shouldn't be there. :)

hi 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
Ben Jakuben
Treehouse Teacher

It 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.

Ben, got it thanks...

I'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;       
}

Nevermind, I realized the else statement does not require:

(cell.accessoryType == UITableViewCellAccessoryCheckmark)

yes .. i think Ben will update...