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.
Hey Bruce,
So you're creating a custom header cell then right?
If so, then just override the setupSize method. That will fire off whenever the size of the cell changes, and you can have all your layout logic in there.
-SteveZ
Steve, thanks for the very quick reply!
I'm using "-(IGGridViewHeaderCell *)gridView:(IGGridView *)gridView headerCellAt:(NSInteger)column", to create my header cells "on the fly". I don't know how I might take advantage of the setupSize method in this case as I'm not deriving (i.e. creating an explicit customized cell) from IGGridViewCell (like I see being done in the sample code).
Bruce
Ok, in that case, I'd highly recommend creating a custom header cell. Just derive from IGGridViewHeaderCell. That way you can centralize your header layout code, and also customize it to dynamically size.
Then you'd simply return that cell from within headerCellAt method, instead of a standard IGGridViewHeadercell.
Stephen, I will need to test this out. At this point, it might be a little while due to some other priorities for me to confirm if this will do what we need, but it sounds reasonable. Thank you.
Hello ,
Have you been able to test Stephen’s suggestions. Do you need any further assistance on this matter ?
Please do not hesitate to contact with us if you need any further assistance on this issue.
I've been sidetracked (although, you could say sideswiped) with other aspects of this and other projects for the moment. Such is life of the enterprise developer! However, trying to see if this works for me is one of my higher priorities once I can focus back in this area of the project. I hope to be able to confirm this solution within the next week or so.
At least I was able to see that, using the IG sample code, changing the orientation will fire off the setupSize method. Assuming I properly get the cell creating done in the new class, I think this could/should work. I'm being cautiously optimistic since our code is a bit different than the sample code and we might have other challenges.
Thank you for checking up, though!
It looks like that did do the trick for us. I've marked it as the answer. Thanks for the follow-ups!