簡體   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