[英]How to change image of imageview in tableview custom cell with pagination.
[英]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];
}
如果您更改单元格imageView
在didSelectRowAtIndexPath
,所以当你滚动您tableView
它不匹配。
所以我的建议是,在NSMutableArray
和cellForRowAtIndexPath
中添加选定的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.