gpt4 book ai didi

swift - 使最后一行的底部成为表格 View 的底部(如果行数足够)

转载 作者:搜寻专家 更新时间:2023-11-01 05:33:14 24 4
gpt4 key购买 nike

有什么办法可以避免 tableview 在到达底部单元格时继续滚动?

到目前为止,我设法做到了这一点:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if indexPath.row == dataArray.count - 1 {
tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
}
}

这只允许我在用户将表格“滚动”到底部时停止滚动。但之后用户可以再次滚动。只有我可以禁用“向下”滚动,我才能实现它。移动后立即再次启用它。

但是这样做似乎需要做很多工作,也许我遗漏了一些将最后一个单元格底部固定到 tableview 底部的属性。

有什么想法吗?

最佳答案

您需要做 3 件事。

tableView.footerView = UIView()
tableView.bounces = false

在重新加载 tableView 之后。tableViewHeight(你的约束).constant = tableView.contentSize.height

这将导致 tableView 仅显示填充的单元格,您将限制高度与内容一样高,并且您不能弹跳内容,因为您希望它在最后一个单元格处停止。

关于swift - 使最后一行的底部成为表格 View 的底部(如果行数足够),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49768804/

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