如果我为之前的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];
}
答案 0 :(得分:1)
如果您在imageView
中更改了单元格didSelectRowAtIndexPath
,那么当您滚动tableView
它不匹配时。
所以我的建议是在indexPath
和NSMutableArray
中添加选定的cellForRowAtIndexPath
检查该数组是否包含选定的indexPath
,如果它包含设置radio_check
的图像,否则设置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];
}