19

我正在尝试扩展 UITableViewCell 以显示更多内容。到目前为止,我已经完成了动画,但我的问题是新内容在动画完成之前出现。这是我的代码:

ps 在配置单元格时,描述标签和阅读按钮都以隐藏状态开始。

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.selectedRow = indexPath;
    SDJCell *cell = (SDJCell *)[tableView cellForRowAtIndexPath:indexPath];
    [tableView beginUpdates];
    [tableView endUpdates];
    cell.descriptionLabel.hidden = NO;
    cell.readButton.hidden = NO;
}

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    SDJCell *cell = (SDJCell *)[tableView cellForRowAtIndexPath:indexPath];
    [tableView beginUpdates];
    [tableView endUpdates];
    cell.descriptionLabel.hidden = YES;
    cell.readButton.hidden = YES;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(selectedRow && indexPath.row == selectedRow.row) {
    return 100;
    }
    return 44;
}

关于在单元格完成扩展后如何显示这些额外内容的任何想法?

谢谢!!

4

1 回答 1

26

我有同样的问题。解决方案是设置单元格的自动调整大小掩码,以便它与超级视图一起调整大小。

cell.autoresizingMask = UIViewAutoresizingFlexibleHeight;
cell.clipsToBounds = YES;

您也可以在 sotoryboard 中执行此操作,两个标志都可以在身份检查器下设置

于 2012-04-19T02:26:58.493 回答