繁体   English   中英

更改Tableview单元格中选定索引处的Imageview图像

[英]Change Imageview image in tableview cell at selected index

如果我选择另一个cell图像与上一个cell相同,请帮帮我。

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

    VoteDeatailTableViewCell *cell = [_voteTable dequeueReusableCellWithIdentifier:@"VoteDeatailTableViewCell"];
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.imgRadio.image  = [UIImage imageNamed:@"radio_uncheck"];
    return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    VoteDeatailTableViewCell *cell = [_voteTable cellForRowAtIndexPath:indexPath];
    cell.imgRadio.image  = [UIImage imageNamed:@"radio_check"];

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

如果您更改单元格imageViewdidSelectRowAtIndexPath ,所以当你滚动您tableView它不匹配。

所以我的建议是,在NSMutableArraycellForRowAtIndexPath中添加选定的indexPath ,如果该数组包含radio_check图像,则检查该数组是否包含选定的indexPath否则,如下所示设置radio_uncheck图像。 全局定义NSMutableArray

NSMutableArray *arrSelectedImages = [[NSMutableArray alloc] init];


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    VoteDeatailTableViewCell *cell = [_voteTable dequeueReusableCellWithIdentifier:@"VoteDeatailTableViewCell"];
    cell.contentView.backgroundColor = [UIColor clearColor];

    if ([arrSelectedImages containsObject:indexPath]) {
        cell.imgRadio.image  = [UIImage imageNamed:@"radio_check"];
    }
    else {
        cell.imgRadio.image  = [UIImage imageNamed:@"radio_uncheck"];
    }

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [arrSelectedImages removeAllObjects];
    [arrSelectedImages addObject:indexPath];
    [self.tblVW reloadData];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM