PrototypeHeightStrategy improvements

This commit is contained in:
Max Sokolov 2016-09-02 21:42:34 +03:00
parent 70d6cb8d73
commit 1be65d18ad
1 changed files with 13 additions and 2 deletions

View File

@ -49,7 +49,14 @@ public class PrototypeHeightStrategy: CellHeightCalculatable {
return height
}
guard let cell = tableView.dequeueReusableCellWithIdentifier(row.reuseIdentifier) else { return 0 }
var prototypeCell = prototypes[row.reuseIdentifier]
if prototypeCell == nil {
prototypeCell = tableView.dequeueReusableCellWithIdentifier(row.reuseIdentifier)
prototypes[row.reuseIdentifier] = prototypeCell
}
guard let cell = prototypeCell else { return 0 }
cell.bounds = CGRectMake(0, 0, tableView.bounds.size.width, cell.bounds.height)
@ -66,7 +73,11 @@ public class PrototypeHeightStrategy: CellHeightCalculatable {
}
public func estimatedHeight(row: Row, path: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
if let estimatedHeight = row.estimatedHeight where estimatedHeight > 0 {
return estimatedHeight
}
return height(row, path: path)
}
public func invalidate() {