How to reach the current selected cell in didSelectRowAtIndexPath?

前端 未结 6 1727
迷失自我
迷失自我 2021-02-01 00:10

I want to change the accessory view type of a cell through the method: didSelectRowAtIndexPath , i.e. when a row is selected I want to change the accessory view type, can I do t

6条回答
  •  我在风中等你
    2021-02-01 00:59

    Store selected indexpath. for eg: NSInteger selectedIndexPath; then follow the step below. set your accessory view.

    -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     {
        AddressTableViewCell *cell=(AddressTableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
        cell.backgroundColor=[UIColor lightGrayColor];
    
        Address *addr=[self.locationArray objectAtIndex:indexPath.row];
    
        cell.titleLabel.text = addr.addressTitle;
        cell.detailLabel.text = addr.addressDetail;
    
            if (indexPath.row == selectedIndexPath) {
                [cell.selectButton setImage:[UIImage imageNamed:@"checkboxFilled"] forState:UIControlStateNormal];
            }
            else {
                [cell.selectButton setImage:[UIImage imageNamed:@"checkbox"] forState:UIControlStateNormal];
    
            }
    
        return cell;
    }
    
    
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
        selectedIndexPath=indexPath.row;
    
        [self.tableView reloadData];
    
    }
    

提交回复
热议问题