0

I'm trying to save save the state of the UITableViewAccesoryType I have two cells in two sections. This section (the top) has the two options http://cl.ly/6DVQ bit.ly or j.mp. The two cells below are the username and whatnot. I have tried this here How to preserve the index path value in the table view in iPhone? but it was for saving the state of all the cells and not allowing me to click one cell and uncheck the other. I'm trying to save it to NSUserDefaults so I can pull up the selected cell and use it in a different view controller. Anyone have any ideas on how I can accomplish? As usual, sample code and tutorials are helpful.

Thanks

Community
  • 1
  • 1
Frankrockz
  • 594
  • 1
  • 6
  • 24
  • Well, half the questions haven't been answered, yet. What i'm trying to do is save the accessoryCheckmark and which cell is selected to NSUserDefaults and when the view loads again it sets the accessory type to the cell. – Frankrockz Apr 22 '11 at 23:57

1 Answers1

0

Ok, after reading your comment here is how I would do this:

// In the didSelectCell: method
if (indexPath.section == 0) {
    [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:indexPath.row] forKey:@"ShortingService"];
}

// In "cellForRowAtIndexPath:"
if (indexPath.section == 0) {
   int selectedRow = [[[NSUserDefaults standardUserDefaults] objectForKey:@"ShortingService"] intValue];
   if (indexPath.row == selectedRow)
      cell.accessoryType = UITableViewCellAccessoryTypeCheckmark;
}
Robin
  • 8,197
  • 11
  • 45
  • 74