gpt4 book ai didi

ios - TableView - heightForRowAtIndexPath 未被调用

转载 作者:可可西里 更新时间:2023-10-31 23:53:05 26 4
gpt4 key购买 nike

在完成所有其他 Stack Overflow 表单之后,我为我的一个单元格实现了动态高度,如下所示:

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

if(indexPath.row == 1){
var image : UIImage = maskRoundedImage(image: UIImage(named: "Temp_Profile.png")!, radius: 150)
cell.imageView?.image = image
return cell
}
cell.textLabel?.text = TableArray[indexPath.row]
cell.backgroundColor = UIColor.init(colorLiteralRed: 0.56, green: 0, blue: 0.035, alpha: 1)
cell.textLabel?.textColor = UIColor.white
cell.textLabel?.font = UIFont(name: "Helvetica", size: 28)

return cell
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == 1 {
return UITableViewAutomaticDimension * 3

}
return UITableViewAutomaticDimension
}

这看起来很简单,但调试 session 显示从未调用过 heightForRowAtIndexPath。 View Controller 是一个 UITableViewController,其他一切正常。你们有没有看到这个函数没有被调用的原因?

谢谢你的帮助!

最佳答案

在 Swift 3 中,签名是:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat

您有旧签名,因此无法识别。

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 1 {
return UITableViewAutomaticDimension * 3

}
return UITableViewAutomaticDimension
}

关于ios - TableView - heightForRowAtIndexPath 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42006650/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com