0

当我们单击相应单元格应该展开的任何单元格时,我正在创建可展开的表格视图,如果我们单击同一个单元格它应该折叠。直到这个工作正常。在每个单元格中,我都有一些在自定义单元格笔尖中采用的 UI 元素。我的问题是当我单击最后一个单元格时,它显示了元素,但是当我单击上面的单元格时,UI 元素没有显示它显示为空白。这是我在 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;
}

}

这是我在选择表格中的单元格后尝试显示的内容。这里 _expandableCells 是一个 NSmutableArray。提前致谢

4

1 回答 1

0

尝试将所有单元配置代码移动到cellForRowAtIndexPath:

像这样:

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;
于 2015-02-16T07:42:46.943 回答