![](/img/trans.png)
[英]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.