DidselectRowAtIndexPath适用于tableview中的选定单元格

时间:2015-02-16 07:01:58

标签: ios objective-c uitableview didselectrowatindexpath heightforrowatindexpath

当我们点击相应单元格应该展开的任何单元格时,我创建了可扩展的tableview,如果我们单击它应该折叠的相同单元格。这个工作正常。在每个单元格中,我在自定义单元格笔尖中采用了一些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。提前致谢

1 个答案:

答案 0 :(得分: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;