[英]Change Imageview image in tableview cell at selected index
If I select another cell
image stays same for the previous cell
, please help me out. 如果我选择另一个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];
}
If you change your cell imageView
in didSelectRowAtIndexPath
so when you scroll your tableView
it mismatched. 如果您更改单元格imageView
在didSelectRowAtIndexPath
,所以当你滚动您tableView
它不匹配。
so my suggestion is that add selected indexPath
in NSMutableArray
and in cellForRowAtIndexPath
check that array contains selected indexPath
if it contains than set radio_check
image otherwise set radio_uncheck
image like below. 所以我的建议是,在NSMutableArray
和cellForRowAtIndexPath
中添加选定的indexPath
,如果该数组包含radio_check
图像,则检查该数组是否包含选定的indexPath
否则,如下所示设置radio_uncheck
图像。 Define NSMutableArray
globally. 全局定义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.