0

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?

SwiftyJD
  • 5,257
  • 7
  • 41
  • 92
  • Why don't you just add the view behind the tableview rather than a specific cell? – Paulw11 Aug 10 '20 at 20:46
  • @Paulw11 I tried that approach initially, its because its a sticky header and has specific behavior when scrolling. – SwiftyJD Aug 10 '20 at 20:56
  • You can use another design for topmost cell, or if your header is not a complex view you can just add all of your cells and hide/show when you return your cell in `cellForRowAt` method – Ekrem Duvarbasi Aug 10 '20 at 21:40

1 Answers1

0

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
        }
    }
}
The Mach System
  • 6,703
  • 3
  • 16
  • 20