IOS UITableView Check One Cell


/ Published in: iPhone
Save to your folder(s)

Only allows one table view cell to be checked.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.