0

I have tab bar in which one tab has a UINavigationController that is assigned a root view controller which consists of a UITableView that drills down to more choices. After i select an item in my root view controller i am given another uitableview and i use the following to assign only one checkmark to that section or group using the following code in my cellForRowAtIndexPath.

if([self.checkedIndexPath isEqual:indexPath])
{
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
    cell.accessoryType = UITableViewCellAccessoryNone;
}

and the following in didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Uncheck the previous checked row
if(self.checkedIndexPath)
{
    UITableViewCell* uncheckCell = [tableView
                                    cellForRowAtIndexPath:self.checkedIndexPath];
    uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
self.checkedIndexPath = indexPath;

[tableView deselectRowAtIndexPath:indexPath animated:YES];
}

My Problem is that when i use the back button on my navigation menu and go back to the same UItableview, the checkmark disappears. however this is not the case when i scroll up and down in that view. How do i keep those checkmarks there when i go back and forth using my navigation controller.

1 Answers1

1

I believe you're having this issue because you are pushing a new UIViewController instance whenever you go back and forth - the new instance doesn't know what the previous checkedPath property was.

To solve this you need to either:

  1. Persist the checked row value somehow (NSUserDefaults, CoreData, etc..). This way any instance would get the same checked row value
  2. Re-use the same view controller when pushing.
Edwin Iskandar
  • 4,119
  • 1
  • 23
  • 24
  • Wow this helped me a lot. Thank you so much Edwin. Now the only problem is that when i select a cell, the checkmark is used in other 'categories' that i drill down. So say if i have 3 cells/rows in my root view, if i select cell two (in detail view) inside cell one (in root view) of these cells/rows it changes the checkmark of cells two and three (in root view) – Sero Eskandaryan Nov 24 '12 at 06:38
  • And I found out the solution to that also :) Thanks Edwin – Sero Eskandaryan Nov 24 '12 at 07:12