How to determine when the cells in a tableView are returned so as to add a uiview after its finished?

25 Views Asked by At

I'm working with some legacy code and it looks like they added a custom sticky header view in the viewDidLoad. The issues is that I need to add the sticky header view AFTER the other cells are returned so that I may send the sticky header view to the back of the other cells so it can be used as a background for the topmost cell.

like so:

 homeScreenTableView.sendSubviewToBack(headerView)

or

homeScreenTableView.insertSubview(headerView, at: 0)

The issue is there is no call back after the cells are returned in a tableView. I know this is a bit hacky, but is there a way to do this?

1

There are 1 best solutions below

0
The Mach System On

You check if the last indexPath in indexPathsForVisibleRows array has been displayed on screen.

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if let lastVisibleIndexPath = tableView.indexPathsForVisibleRows?.last {
        if indexPath == lastVisibleIndexPath {
            // finished loading
        }
    }
}