improve hash

This commit is contained in:
Max Sokolov 2016-06-16 22:45:33 +03:00
parent 0d7d97db57
commit d4efb6a679
1 changed files with 12 additions and 8 deletions

View File

@ -41,23 +41,27 @@ public class PrototypeHeightStrategy: CellHeightCalculatable {
}
public func height(row: Row, path: NSIndexPath) -> CGFloat {
if let height = cachedHeights[row.hashValue] {
guard let tableView = tableView else { return 0 }
let hash = row.hashValue ^ Int(tableView.bounds.size.width).hashValue
if let height = cachedHeights[hash] {
return height
}
guard let cell = tableView?.dequeueReusableCellWithIdentifier(row.reusableIdentifier) else { return 0 }
cell.bounds = CGRectMake(0, 0, tableView?.bounds.size.width ?? 0, cell.bounds.height)
guard let cell = tableView.dequeueReusableCellWithIdentifier(row.reusableIdentifier) else { return 0 }
cell.bounds = CGRectMake(0, 0, tableView.bounds.size.width, cell.bounds.height)
row.configure(cell, isPrototype: true)
cell.setNeedsLayout()
cell.layoutIfNeeded()
let height = cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height + (tableView?.separatorStyle != .None ? separatorHeight : 0)
let height = cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).height + (tableView.separatorStyle != .None ? separatorHeight : 0)
cachedHeights[row.hashValue] = height
cachedHeights[hash] = height
return height
}