为什么不改变rowheight?

时间:2018-01-13 23:36:36

标签: ios swift uitableview firebase grand-central-dispatch

控制台记录正确的行高,以便正确地在tableview中显示正确的行高。 ImageURLS是一个字符串数组,包含来自Firebase Storage的下载imageURLS。

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Reuse", for: indexPath) as! TableViewCell

    // Configure the cell...
    ///////////////////////

    let downloadURL = URL(string: self.imageURLS[indexPath.row]) 
    URLSession.shared.dataTask(with: downloadURL!) { (data, _, _) in
        if let data = data {
            let image = UIImage(data: data)
            DispatchQueue.main.async {
                cell.cellImageView.image = image
                cell.cellImageView.contentMode = .scaleAspectFit
                let aspectRatio = Float((cell.cellImageView?.image?.size.width)!/(cell.cellImageView?.image?.size.height)!)
                print("aspectRatio: \(aspectRatio)")
                tableView.rowHeight = CGFloat(Float(UIScreen.main.bounds.width)/aspectRatio)
              print("tableView.rowHeight: \(tableView.rowHeight)")
            }
        }
        }.resume()


    ///////////////////////
    return cell
}

0 个答案:

没有答案