Posted By

bethjt1220 on 05/09/11


Tagged

ios


Versions (?)

IOS UITableView Check One Cell


 / Published in: iPhone
 

Only allows one table view cell to be checked.

  1. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  2.  
  3. if(_lastIndex != nil)
  4. {
  5. UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:_lastIndex];
  6. if(oldCell.accessoryType == UITableViewCellAccessoryCheckmark)
  7. {
  8. oldCell.accessoryType = UITableViewCellAccessoryNone;
  9. }
  10. }
  11.  
  12. UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
  13. if(newCell.accessoryType == UITableViewCellAccessoryNone) {
  14. newCell.accessoryType = UITableViewCellAccessoryCheckmark;
  15. }
  16.  
  17. _lastIndex = indexPath;
  18. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  19. }

Report this snippet  

You need to login to post a comment.