我使用UITableView
来显示来自领域的数据。我有两种类型的第一排UIImageView
和其他没有UIImageView
。如果形象UIImageView
行的高度应为207或UIImageView
是零行的高度应为64如何使用tableviewcell的动态高度
我的编码:
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return msgs.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! collCell
let msg = msgs[indexPath.row]
var decodeImgURL = ""
cell.lbl1.text = msg.content
decodeImgURL = msg.imgurl
if decodeImgURL == "none" {
cell.img.isHidden = true
} else {
let dataDecoded : Data = Data(base64Encoded:decodeImgURL,options: .ignoreUnknownCharacters)!
let decodedImage = UIImage(data: dataDecoded)
cell.img.image = decodedImage
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let cell = tableView.cellForRow(at: indexPath) as! collCell
if cell.img.image != nil {
return 207
} else {
return 64
}
}
我得到一个错误的let cell = tableView.cellForRow(at: indexPath) as! collCell
@Moritz确定我理解 –