UITableview 多选 解决cell重用问题

来源:互联网 发布:蜂鸟众包一键抢单软件 编辑:程序博客网 时间:2024/05/21 03:25

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

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

    PERenewalGetViewCell * selectCell = (PERenewalGetViewCell*)[tableView cellForRowAtIndexPath:indexPath];    [tableView deselectRowAtIndexPath:indexPath animated:YES];        if (_selectIndexArray.count == 0) {        [_selectIndexArray addObject:indexPath];    }else{        for (int a = 0 ; a < _selectIndexArray.count ; a++) {            //deleteElemnet = YES;            if ([_selectIndexArray[a] isEqual:indexPath]) {                [_selectIndexArray removeObject:indexPath];                deleteElemnet = NO;                [selectCell.selectButton setBackgroundImage:[UIImage imageNamed:@"mobilePhoneValidate_frame_n"] forState:UIControlStateNormal];            }        }                if (deleteElemnet == YES) {            [_selectIndexArray addObject:indexPath];            deleteElemnet = NO;            [selectCell.selectButton setBackgroundImage:[UIImage imageNamed:@"mobilePhoneValidate_frame_s"] forState:UIControlStateNormal];        }    }    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];

    }

 
0 0
原创粉丝点击