xcode 扩展 UITableViewCell

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10220565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:01:03  来源:igfitidea点击:

Expanding UITableViewCell

iosxcodeuitableview

提问by Sean Danzeiser

I am trying to expand a UITableViewCell to reveal more content. So far i've got the animation down, but my problem is the new content appears before the animation is complete. Here is my code:

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

ps the description label and read button both start off as hidden when the cell is configured.

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;
}

Any ideas for how I can reveal this extra content after the cell is done expanding??

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

Thanks!!

谢谢!!

回答by aryaxt

I had the exact same problem. The solution is to set the autoresizing mask of the cell, so that it resizes along with its superview.

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

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

you could also do this in sotoryboard, both flags can be set under identity inspector

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