Ios 当tableView高度为真实高度时

Ios 当tableView高度为真实高度时,ios,swift,Ios,Swift,谢谢你的帮助 我使用Nib处理TablViewCell,但当我尝试在cell.contentView中绘制图形时,我无法在awakeFormNib()中获得真实高度,因此如何获得真实高度以绘制正确的图形 该单元是一个动态单元,我使用UITableViewCell+FDTemplateLayoutCell。您可以在单元子类中添加该单元并获得真实高度: -(void)layoutSubviews { [super layoutSubviews]; // Get frame: sel

谢谢你的帮助

我使用Nib处理TablViewCell,但当我尝试在cell.contentView中绘制图形时,我无法在awakeFormNib()中获得真实高度,因此如何获得真实高度以绘制正确的图形


该单元是一个动态单元,我使用UITableViewCell+FDTemplateLayoutCell。

您可以在单元子类中添加该单元并获得真实高度:

-(void)layoutSubviews {
    [super layoutSubviews];

    // Get frame: self.contentView.frame
}
并加载nib单元。首先,注册nib:

[self.tableView registerNib:[UINib nibWithNibName:@"CustomCellNibName" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CustomCellReuseIdentifier"];
表格视图中加载nib:cellForRowAtIndexPath

id cell  = [self dequeueReusableCellWithIdentifier:@"CustomCellReuseIdentifier"];

if (cell == nil) {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellNibName" owner:self options:nil];
    for (id currentObject in topLevelObjects){
        if ([currentObject isKindOfClass:[CustomCell class]]){
            cell =  currentObject;
            break;
        }
    }
}
相信你能把它转换成Swift


您可以在cell子类中添加此项并获得真实高度:

-(void)layoutSubviews {
    [super layoutSubviews];

    // Get frame: self.contentView.frame
}
并加载nib单元。首先,注册nib:

[self.tableView registerNib:[UINib nibWithNibName:@"CustomCellNibName" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CustomCellReuseIdentifier"];
表格视图中加载nib:cellForRowAtIndexPath

id cell  = [self dequeueReusableCellWithIdentifier:@"CustomCellReuseIdentifier"];

if (cell == nil) {
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCellNibName" owner:self options:nil];
    for (id currentObject in topLevelObjects){
        if ([currentObject isKindOfClass:[CustomCell class]]){
            cell =  currentObject;
            break;
        }
    }
}
相信你能把它转换成Swift


当我使用Nib时,我会拖动与iPhone不同大小的手机,当我在phone中运行演示时,第一个大小是Nib手机大小,而不是手机大小,即使在layoutSubview基金中也是如此,所以我如何在Nib中设置真实大小。@Eggplant如何初始化手机?注册Nib。当我使用func layoutSubview()时,我犯了一个错误,我使用子视图框架绘制一条线。Cell.contentView.frame是正确的,但子视图框架是错误的。当我使用Nib时,我会用iPhone拖动不同大小的单元格,当我在phone中运行演示时,第一个大小是Nib单元格大小,而不是手机大小,即使在layoutSubviews基金中也是如此,所以如何在Nib中设置真实大小。@Eggplant如何初始化单元格?注册Nib。我犯了一个错误,使用func layoutSubview()时,我会使用子视图框架绘制一条线。Cell.contentView.frame正确,但子视图框架错误。