天天看点

UITableview 多选 解决cell重用问题

原文地址:http://blog.csdn.net/u011254628/article/details/18089503

假如  我们有100个cell  这时肯定 是需要重用的

解决方案 在  didselesctCell  中记录所选择的   indexPath 

[objc]  view plain copy

UITableview 多选 解决cell重用问题
UITableview 多选 解决cell重用问题
  1. PERenewalGetViewCell * selectCell = (PERenewalGetViewCell*)[tableView cellForRowAtIndexPath:indexPath];  
  2. [tableView deselectRowAtIndexPath:indexPath animated:YES];  
  3. if (_selectIndexArray.count == 0) {  
  4.     [_selectIndexArray addObject:indexPath];  
  5. }else{  
  6.     for (int a = 0 ; a < _selectIndexArray.count ; a++) {  
  7.         //deleteElemnet = YES;  
  8.         if ([_selectIndexArray[a] isEqual:indexPath]) {  
  9.             [_selectIndexArray removeObject:indexPath];  
  10.             deleteElemnet = NO;  
  11.             [selectCell.selectButton setBackgroundImage:[UIImage imageNamed:@"mobilePhoneValidate_frame_n"] forState:UIControlStateNormal];  
  12.         }  
  13.     }  
  14.     if (deleteElemnet == YES) {  
  15.         [_selectIndexArray addObject:indexPath];  
  16.         deleteElemnet = NO;  
  17.         [selectCell.selectButton setBackgroundImage:[UIImage imageNamed:@"mobilePhoneValidate_frame_s"] forState:UIControlStateNormal];  
  18.     }  
  19. }  
  20. deleteElemnet = YES;  

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

 中

#pragma mark - 是否勾选对号 解决重用问题

    if([_selectIndexArraycontainsObject:indexPath]){

        cell.accessoryType=UITableViewCellAccessoryCheckmark;

        [cell.selectButtonsetBackgroundImage:[UIImageimageNamed:@"mobilePhoneValidate_frame_s"]forState:UIControlStateNormal];

    }else{

        cell.accessoryType=UITableViewCellAccessoryNone;

        [cell.selectButtonsetBackgroundImage:[UIImageimageNamed:@"mobilePhoneValidate_frame_n"]forState:UIControlStateNormal];

    }

上一篇: cell重用
下一篇: cell重用机制