Change UI state on section expand/collapse


#1

I need to add an icon to my section header that changes based on if the section is expanded or collapsed.

I can add the image view to the my custom header that is returned in GetHeaderView, but I don’t know how to make sure that the image’s state matches that of the section collapsed state.

I tried calling grid.SectionIsCollapsed(section) from within GetHeaderView, but it doesn’t match what I expected. I am setting certain sections as collapsed after my grid is setup using Grid.SetSectionAsCollapsed(i, !sectionRoot.Inclusive) but it appears that since this isn’t called until after the sections are initially retrieved that the status isn’t used for the icon.

Also, when tapping a section header to expand/collapse it, is there a way to call to refresh just that section header?


#2

Hi canderson,

Unfortunately sectionIsCollapsed can’t return accurate results until the grid has finished rendering. Presumably you know which sections are initially collapsed, so you could try using those values initially, then implementing the delegate method didFinishLayingOutShinobiDataGrid: to set a flag showing that you can now use sectionIsCollapsed to determine whether the section is collapsed.

If you change the icon in the shinobiDataGrid:willExpandSectionAtIndex: and shinobiDataGrid:willCollapseSectionAtIndex: delegate methods, the section headers should be redrawn with the sections, though you may need to call setNeedsDisplay.

I hope that helps.

Kind regards,

Alison


#3

I was able to get this working reasonably well based on your suggestions. Instead of relying on sectionIsCollapsed I am always just checking the internal state of the node (which I do how have to update in OnCollapsedSection and OnExpandedSection.

SetNeedsDisplay doesn’t seem to update anything for me when it is called. In the meantime, I am able to call Reload although I am sure that is not an ideal solution.


#4

Have you tried using OnCollapsingSection and OnExpandingSection instead of OnCollapsedSection/OnExpandedSection? If you make the change at that point, I think the section header should be redrawn as the section collapses/expands, without the need for a full Reload call.