OGeek|极客世界-中国程序员成长平台

标题: ios - 检查 UITableViewAutomaticDimension 返回 -1 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:31
标题: ios - 检查 UITableViewAutomaticDimension 返回 -1

在我的代码中,我想决定是使用 UITableViewAutomaticDimension 还是 UITableViewAutomaticDimension + constant,例如:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  if UITableViewAutomaticDimension <= someConst {
    return someConst
  }
  return UITableViewAutomaticDimension
}

但是,似乎每次我检查 UITableViewAutomaticDimension 时它都是-1,但是如果我直接返回值,那么高度就会正确。不可以这样窥视 UITableViewAutomaticDimension 吗?如果 UITableViewAutomaticDimension ,我想检查单元格的高度,然后决定单元格高度返回应该是什么。对此的任何指示将不胜感激!谢谢



Best Answer-推荐答案


我认为你对 UITableViewAutomaticDimension 的理解是错误的。 UITableViewAutomaticDimension 仅适用于自动布局。此外,它不会通过计算返回行的高度,并且总是返回 -1。它只是告诉应该根据单元格的约束来计算 tableview 高度。

检查 this教程以了解有关自调整单元格的更多信息。

关于ios - 检查 UITableViewAutomaticDimension 返回 -1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41534884/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4