Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.09 KB  |  hits: 48  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to properly toggle UITableViewCell's accesoryType on cell selection/deselection?
  2. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  3. {  
  4.     UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  5.     [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
  6. }
  7.  
  8. - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  9. {
  10.     UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  11.     [cell setAccessoryType:UITableViewCellAccessoryNone];
  12. }
  13.        
  14. [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
  15.        
  16. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  17.     {  
  18.         UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  19.         if (cell.accessoryType == UITableViewCellAccessoryCheckmark)
  20.         {
  21.             cell.accessoryType = UITableViewCellAccessoryNone;
  22.         }
  23.         else
  24.         {
  25.             cell.accessoryType = UITableViewCellAccessoryCheckmark;
  26.         }
  27.     }