動態 的 UITableViewCell Height
var heightsCache: Dictionary = [:]
var cellDefaultHeight: CGFloat!
override func viewDidLoad() {
self.tableView.dataSource = self
self.tableView.delegate = self
let scale = UISizeUtils.getScaleFromPlus(self.view)
// height = 621
self.cellDefaultHeight = 621.0 * scale
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = self.cellDefaultHeight
...
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
...
self.heightsCache[indexPath] = newCellHeight
...
}
// MARK: - UITableViewDelegate
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let height = self.heightsCache[indexPath]
if height != nil {
return height!
}else{
return self.cellDefaultHeight
}
}
留言
張貼留言