iosuitableviewtableviewsectionheader

How to highlight/change background color of table view section header while scrolling


I am stuck with displaying the table view section header. Problem is, when I scroll down, until I hit the next section header, I want my previous section header to be highlighted and as soon as I hit the next section header,I want my this "new" section header to be highlighted and my previous section header to be unhighlighted. That, namely, means that I want the header which is displayed at the top to be highlighted while I scroll down and up.

To be more clear, I put related pictures:

1.Current section header is "Section 1" 1.Current section header is "Section 1" This occurs when app starts.

2.Scrolled down but current section header is still same 2.Scrolled down but current section header is still same and should remain so until next section header commences.

3.Scrolled down and passed to next section header.

3.Scrolled down and passed to next section header. This section header should be highlighted since it is at the top of table view now. I put these pictures by taking snapshots and filling red color by using a painting tool. I hope it is clear to understand.


Solution

  • Perhabs you can do it with a trick?

    Determine if a tableview cell is visible

    Just take a look which cells are visible. If a cell of section 2 is visible but no cell of section 1, you know section 2 is at the top.