1

Thanks to help.

I use the Nib to deal with the TablViewCell, but when I try to draw graphics in cell.contentView, I can not get the true height in awakeFormNib(), so how can I get the true height to draw the correct graphics.

The cell is a dynamic cell and I use the UITableViewCell + FDTemplateLayoutCell.

Eggplant
  • 93
  • 9

1 Answers1

0

You can add this in cell subclass and get the true height:

-(void)layoutSubviews {
    [super layoutSubviews];

    // Get frame: self.contentView.frame
}

And load nib cell. First, register nib:

[self.tableView registerNib:[UINib nibWithNibName:@"CustomCellNibName" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"CustomCellReuseIdentifier"];

Load nib in 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;
        }
    }
}

Believe you can convert it to Swift.

When is layoutSubviews called?

tomfriwel
  • 2,575
  • 3
  • 20
  • 47
  • When I use Nib, I drag the Cell Size different size with iPhone, and when I run the demo in phone, the first size is nib cell size, not phone size , even in layoutSubviews fund ,so how can I set the true size in nib. – Eggplant Jun 17 '17 at 06:18
  • @Eggplant How you initialize the Cell? – tomfriwel Jun 17 '17 at 07:28
  • register the Nib. – Eggplant Jun 19 '17 at 02:30
  • I make a mistake,When I use the func layoutSubview(), I draw a line use the subView frame. Cell.contentView.frame is correct, but subview frame is wrong. – Eggplant Jun 21 '17 at 09:01