问题描述
我正在处理一些旧代码,好像他们在viewDidLoad中添加了一个自定义粘性标头视图。问题是我需要在返回其他单元格之后添加粘性标头视图,以便可以将粘性标头视图发送到其他单元格的背面,以便可以用作最顶部单元格的背景。
像这样:
homeScreenTableView.sendSubviewToBack(headerView)
或
homeScreenTableView.insertSubview(headerView,at: 0)
问题是在tableView中返回单元格后没有回调。我知道这有点棘手,但是有办法吗?
解决方法
您检查indexPathsForVisibleRows数组中的最后一个indexPath是否已显示在屏幕上。
func tableView(_ tableView: UITableView,willDisplay cell: UITableViewCell,forRowAt indexPath: IndexPath) {
if let lastVisibleIndexPath = tableView.indexPathsForVisibleRows?.last {
if indexPath == lastVisibleIndexPath {
// finished loading
}
}
}