Dynamic cell height with SDWebImage

不羁的心 提交于 2019-11-28 12:54:18
Milan Nosáľ

You just need to tell the whole tableView to refresh its view. Use this code in the view controller holding the tableView:

func refreshTableView() {
    self.tableView.beginUpdates()
    self.tableView.setNeedsDisplay()
    self.tableView.endUpdates()
}

Using a delegate pattern tell the viewController to refresh the tableView, so something like:

func setCustomImage(image: UIImage) {
    let aspect = image.size.width / image.size.height
    let constraint = NSLayoutConstraint(item: postChart, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: postChart, attribute: NSLayoutAttribute.height, multiplier: aspect, constant: 0.0)
    constraint.priority = UILayoutPriority(rawValue: 999)
    aspectConstraint = constraint
    postChart.image = image

    // call this to refresh table
    delegate.refreshTableView()
}

Post class:

class Post {
    var title : String?
    var source : String?
    var chartURL : String?
    var postChart: UIImage?
    var category : String?
    var rank : CGFloat?
    var imageSize: CGSize?

    init(data: NSDictionary) {
        title = data["title"] as? String
        source = data["source"]as? String
        chartURL = data["chartURL"] as? String
        postChart = data["postChart"] as? UIImage
        category = data["category"] as? String
        rank = data["rank"] as? CGFloat
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!