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
Paul Panayotou
5,001 PointsRibbit Code Challenge Help Needed. Stage 3, Adding Friends by Tapping on a Table View Cell, 1/1
The Challenge: Create a list of shows to download by adding the code below to mark rows as selected or not using 'UITableViewCellAccessoryCheckmark' and 'UITableViewCellAccessoryNone'.
// 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) {
} else {
}
What I don't understand: Why would UITableViewAccessoryCheckmark be required if all the check-marked cells are filtered out of the if condition into the else statement? And wouldn't nothing be done in the if condition since we're looking for check-marked boxes? If that doesn't make sense, that's because I am LOST. Please help. Full answer appreciated if possible. I understood the tutorial, but not getting this one.
Also, can someone please tell me how those nifty screenshots of code from the code challenge are posted in the forums?
Thanks!
3 Answers
Stone Preston
42,016 Pointsyou are right. The else condition would handle the ones marked with checkmarks. Most likely the code challenge engine will only accept an answer that uses 2 ifs that check for UITableViewCellAccessoryCheckmark and UITableViewCellAccessoryNone as stated in the challenge , not an if else. Using the 2 ifs is also a little more explicit which is helpful.
you can see how to post code in a code block here
you dont have to specify a language after the three ` though. you can just go to a new line and start your code block
Paul Panayotou
5,001 PointsThanks for responding! I hope this code blocking works...
I'm still really lost unfortunately. When the row is selected (i.e. didSelectRowAtIndexPath is called), then a checkmark is assigned to cell. So why would one use an "if" to check UITableViewCellAccessoryNone? All of the code in didSelect method will have a checkmark. No?
This is what I've come up with and I don't think it's even close to what I need to do. Please help! If anyone knows the solution, please let me know.
//This code is excerpted from the didSelectRowAtIndexPath method of a view controller
//My comments: so When the row is selected, this code executes.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// Add your code below to make this work!
cell.accessoryType = UITableViewCellAccessoryCheckmark;
//My comments: Creating a list below to store the shows selected, but this can't be right because how
//will its scope extend to the next time a row is selected?
//It has to be a property which I can't do here. How else can I make a list?
NSMutableArray *videoList = [NSMutableArray array];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
[videoList addObject:cell]
//My comments: Could cell be a key for a value?
};
Edit: Yay! the code block works :)
Paul Panayotou
5,001 PointsYes! Nailed it... (duh ha ha)
// 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 = UITableViewCellAccessoryNone;
}