'UITableView bring cells at bottom to front of View Hierarchy

I have a question regarding UITableView and UITableViewCells. The default behavior of iOS is to put the cells on top to the front of the View Hierarchy like in the screen below

enter image description here

Is there a way to make the UITableView to bring the cells at the bottom of the UITableView to the front of the view hierarchy. What I'm looking for is an exact inverse of the Hierarchy in the picture above. The cell at the bottom needs to be the front most view, the cell above it needs to be behind the bottom most and so on.

Or is there a way that I can manually make a cell, using its indexpath, to bring it to the front of the hierarchy.

I tried using bringSubviewToFront but it didn't help.



Solution 1:[1]

I stuck with the same problem and found a solution.

In my case I need to bring to front a cell which is an instance of specified class. Since all cells are just subviews of UITableView, I'm going through its subviews and bring the necessary cells to front:

func tableView(
    _ tableView: UITableView,
    willDisplay cell: UITableViewCell,
    forRowAt indexPath: IndexPath)
{
    tableView.subviews
        .filter { $0 is MyTableViewCell}
        .forEach { tableView.bringSubviewToFront($0) }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexander Perechnev