感谢帮助。
我使用笔尖来处理TablViewCell,但是当我尝试在cell.contentView中绘制图形时,我无法在awakeFormNib((中获取真实的高度,那么我如何获得真实的高度来绘制正确的图形。
该单元格是一个动态单元格,我使用 UITableViewCell + FDTemplateLayoutCell。
您可以在单元格子类中添加此内容并获得真实高度:
-(void)layoutSubviews {
[super layoutSubviews];
// Get frame: self.contentView.frame
}
并加载笔尖电池。首先,寄存器笔尖:
[self.tableView registerNib:[UINib nibWithNibName:@"CustomCellNibName" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CustomCellReuseIdentifier"];
装入tableView: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。
什么时候调用布局子视图?