简体   繁体   中英

DidselectRowAtIndexPath is working for selected cell in tableview

I'm creating expandable tableview when we click any cell the respective cell should expand, if we click the same cell it should collapse. Upto this working fine. In each cell i've some UI element which are taken in the custom cell nib. My issue is when i clicked last cell it showing the elements, but when i click the above cells the UI elements are not displaying it showing blank. Here is my what i've tried in didSelectRowAtIndexPath.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  {
//    selectedIndex = indexPath.row;
[tableView deselectRowAtIndexPath:indexPath animated:YES];

if ([_expandedCells containsObject:indexPath])
{
    [_expandedCells removeObject:indexPath];
}
else
{
    if ([_expandedCells count])
    {
        [_expandedCells removeObjectAtIndex:0];
    }

    [_expandedCells addObject:indexPath];

}
//    [self.voicemailTable reloadRowsAtIndexPaths:[NSArray     arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
//    [self.voicemailTable reloadRowsAtIndexPaths:[self.voicemailTable indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationFade];


[tableView beginUpdates];
[tableView endUpdates];

}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

CGFloat kExpandedCellHeight = 150.0f;
CGFloat kNormalCellHeigh = 60.0f;


if ([_expandedCells containsObject:indexPath])
{

    customCell.playBtn.hidden = NO;
    customCell.minimumLbl.hidden = NO;
    customCell.maximumLbl.hidden = NO;
    customCell.sliderBG.hidden = NO;
    customCell.slider.hidden = NO;

    return kExpandedCellHeight;
}
else
{

    customCell.playBtn.hidden = YES;
    customCell.minimumLbl.hidden = YES;
    customCell.maximumLbl.hidden = YES;
    customCell.sliderBG.hidden = YES;
    customCell.slider.hidden = YES;

    return kNormalCellHeigh;
}

}

This what i'm tried for showing after selecting the cell in the table. Here _expandableCells is an NSmutableArray. Thanks in advance

Try moving all the cell configuration code to cellForRowAtIndexPath:

Like so:

YourCustomCellClass *customCell = [tableView - (id)dequeueReusableCellWithIdentifier: <your cell identifier> forIndexPath:indexPath];
if ([_expandedCells containsObject:indexPath]){
    customCell.playBtn.hidden = NO;
    customCell.minimumLbl.hidden = NO;
    customCell.maximumLbl.hidden = NO;
    customCell.sliderBG.hidden = NO;
    customCell.slider.hidden = NO;
}else{
    customCell.playBtn.hidden = YES;
    customCell.minimumLbl.hidden = YES;
    customCell.maximumLbl.hidden = YES;
    customCell.sliderBG.hidden = YES;
    customCell.slider.hidden = YES;
}
return customCell;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM