nghialv / Hakuba

:cherry_blossom: Cellmodel-driven tableview manager
MIT License
473 stars 40 forks source link

Cell's calculatedHeight is always nil #36

Closed respan closed 8 years ago

respan commented 8 years ago

Hey. I'm using Hakuba and so far it's great, but i think i found a bug. Cell's calculatedHeight property is always nil, even after all this calculations:

private extension CellModel {
    func calculateHeight() -> CGFloat {
        if let height = calculatedHeight {
            return height
        }

        guard let cell = delegate?.getOffscreenCell(reuseIdentifier) else {
            return estimatedHeight
        }

        cell.configureCell(self)

        let width = delegate?.tableViewWidth() ?? UIScreen.mainScreen().bounds.width
        cell.bounds = CGRectMake(0, 0, width, cell.bounds.height)
        cell.setNeedsLayout()
        cell.layoutIfNeeded()

        let size = cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
        return size.height + 1
    }
}

I think you should set it to a value before returning from function.

nghialv commented 8 years ago

@respan Great! Many thanks for your reporting. I have just fixed this bug and released a new version.