Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
425
How can a cell in the header row be refreshed when orientation changes?
posted

Basically, I have a situation where I have a header cell that needs to recalculate how to display itself depending on the orientation that the user has set the device. Is there something I can call that will force the header (or just a single header cell) to be refreshed?

Now, for the details because I know that someone will be curious as to why this has to be done at all. I needed to institute my own sorting mechanism for the data (I did not want to just sort what was in the grid but I need to go back to the server to make sure I have the full list of data for a proper sort). My grid has column headers and each column needs to indicate if its part of an ASC or DESC sort (only 1 column for this grid) with a small up/down arrow icon. Well, that arrow icon needs to append itself to the right of whatever label text is in the header cell. That all works wonderfully well.

The problem comes when I want to center the header text. Since I had to customize the header cell to create a UILabel and a UIImageView, I had to figure out a way to make sure they centered properly (actually, it's just UILabel text that needs to center and the arrow can appear to the right of that). I tried a number of things, and probably due to ignorance I couldn't figure out a clever way to have the UILabel auto-center so I just calc'd it based on the column width and width of the text (using a special formula to deal with the font, etc.). The only problem column where this is an issue is the one where the column width can adjust based on the orientation. Whatever the initial orientation of the device is, is where the header ends up as "centered" and won't change when the orientation changes.

For the record, I tried being clever and creating another view with only a UILabel and UIImageView in it, using constraints to properly center them. But, when I tried to add the view of that view controller to the cell view I got bizarre results of the cell placement and before I beat my head on the wall too much, I gave up on that tactic. I also, got this artifact in the center of the entire header that I couldn't explain.

Parents Reply Children