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

Jamie Baker
Jamie Baker
5,703 Points

I'm really stuck on this question...

We are working on an app to download videos of the Treehouse Show, which are listed in a table view. The user will tap on items in the list to create a list of shows to download. For each tap, add code below to simply mark rows as selected or not using 'UITableViewCellAccessoryCheckmark' and 'UITableViewCellAccessoryNone'.

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

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

}
else {

}

I tried "[tableView addObject:cell]" in the else section of the block but it didn't work. Help welcomed!!

2 Answers

Stone Preston
Stone Preston
42,016 Points

I think all you need to do is mark the cell as selected or not. In the if statement you check and see if the cell currently has a checkmark. If it does not have a checkmark, you need to add one. If it does have a checkmark, you need to remove it

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

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

if (cell.accessoryType == UITableViewCellAccessoryNone) {

         //since the cell currently does not have a checkmark, add one here
        cell.accessoryType = UITableViewCellAccessoryCheckmark;

} else {

     //the cell does have a checkmark remove it
     cell.accessoryType = UITableViewCellAccessoryNone
}
          if (cell.accessoryType == UITableViewCellAccessoryNone) {
      cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else
    {
      cell.accessoryType = UITableViewCellAccessoryNone;

    }