Is there a standard way to display aggregate cell values in section headers, aligned with the cell in question, which supports horizontal scrolling, and supports expandable/collapsible sections?
Right now I can almost make it happen by overriding gridView:viewForSectionHeader, and returning a built-up view of UILabels positioned based on the IGCellPath of the first row of cells. However, it doesn't work when there is horizontal grid scrolling; the section header doesn't scroll along with the grid, which kind of makes sense because then how would the section title show.
I could alternatively just change the section title text to something like: "Section A: AggValue1:123.45 AggValue2:678.90", but that doesn't align up with the cells, which seems to be the limiting issue in all this.
Any other ideas that could work to simulate a section header that shows aggregate cells values aligned with the cell in question, horizontally scrolls well, and supports expandable/collapsible sections?
Thanks.
There isn't a built in way to do this. But, I wouldn't rule out the possibility through custom code.
I haven't tested this out, but you could potentially try the following.
1. I'd create a custom IGGridViewSectionHeaderCell, instead of using the delegate gridView:viewForSectionHeader: And in that cell, i'd put an additional IGGridView, that contains your display values. If you have the same amount of columns and the same widths, then they'll automatically line up. I'd also disable UserInteraction on the grid, as you don't want it to be interactive.
2. On the main IGGridView, i'd use the delegate method, scrollViewDidScroll pathsForVisibleRows. I'd then check the first row, and last row in that returned array to find out the first visible and last visible section.
3. Now, in scrollViewDidScroll, you can look up those section cells, they'll have the following path: row:kSectionHeaderIndex column: -1 section:(the actual section index). I'd then update that internal section grid's contentOffset.x to match the contentOffset of the main grid.
Let me know if any of this doesn't make any sense :)
-SteveZ
Yes, that makes perfect sense. Great idea. I'll give it a try and let you know.
I've got most of it working except for a minor issue in the scrolling part...
pathsForVisibleRows only returns me the last row/section if all the sections are collapsed and all of those are in the visible area. Put alternately, pathsForVisibleRows does not include the collapsed sections that appear first in the visible area until a visible non-collapsed/last section is encountered.
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
if ([scrollView isKindOfClass:[IGGridView class]]) {
IGGridView *grid = (IGGridView*)scrollView;
NSArray *rowPaths = [grid pathsForVisibleRows]; // does not include the sections that are collapsed *****
if (rowPaths) {
IGRowPath *firstRow = rowPaths.firstObject;
IGRowPath *lastRow = rowPaths.lastObject;
int firstSectionIndex = firstRow.sectionIndex;
int lastSectionIndex = lastRow.sectionIndex;
for (int i = firstSectionIndex; i < lastSectionIndex + 1; i++) {
MySectionHeaderAggregateCell *sectionHeaderCell = [grid cellAtPath:[IGCellPath pathForRow:kSectionHeaderIndex inSection:i inColumn:-1]];
[sectionHeaderCell.grid setContentOffset:CGPointMake(grid.contentOffset.x, sectionHeaderCell.grid.contentOffset.y)];
}
Any ideas on how to get a reference to those visible collapsed section header cells that don't come over in paths for visible rows? I suppose I could try and just do it for all section header cells, any maybe test if they are visible, and scroll all of them.
Ah, yea, i forgot that you used the Expandable Sections feature :)
Well, the pathsForVisibleRows was more of a shortcut, but you could just loop through all of your section headers, and see if cellAtPath: returns a cell for a particular section. This could be a bit expensive if you have a LOT of sections though.
I suppose another trick that should work is: to use pathForRowAtPoint:
You could pass in the contentOffset.y of the gridView for the top most row, and the contentOffset.y + gridView.bounds.size.height for the bottom most row
Then you could use the returned path to determine the top most section and the bottom most section.
pathForRowAtPoint seems to work well.
One issue I noticed was that if the last row is in view (collapsed or not), the last row path is nil when I use:
IGRowPath *lastRow = [grid pathForRowAtPoint:CGPointMake(0, grid.contentOffset.y + grid.bounds.size.height)];
In that case, I set the last section index to my total number of sections - 1. Then I loop like previous through the section headers to scroll them.
Since I want the first column of the section header grid to be fixed as I scroll horizontally, I will attempt to fix that column, and everything should be perfect.
Hello,
As far as I understand from your post you’ve been able to solve your issue.
Please do not hesitate to contact with us if you have any further questions.