How do you collapse sections? I know there's three-or-so data source methods. One of them returns a BOOL, and it works... but is there a way to programmatically collapse or check the state of a collapsed section? The other two delegate methods seem like they're there for me to implement... and it would seem like the grid data source helper implements some magic. Right now, my solution is crude... I keep a mutable array of @(BOOL) and add a tap gesture recognizer to a custom section cell. It's a huge pain... please tell me I'm doing it wrong.
Please, publish the source to all your data source helpers. That source code would add an extra layer of code-based documentation, likely answering questions such as, "how did they expect us to interact with that control?"
You have to set the expandable property to true on the cell when you create it.
-(IGGridViewSectionCell *)gridView:(IGGridView *)gridView cellForSectionHeader:(NSInteger)section
{
IGGridViewSectionHeaderCell* cell = [IGGridViewSectionHeaderCell gridView:gridView cellForSectionHeader:section];
cell.expandable = self.allowSectionExpansion;
return cell;
}
-SteveZ
I couldn't get IGGridViewSectionHeaderCell to ever call expandSection/collapse. Even now, if I comment out cellForSectionHeader and let the grid create it's own, it still doesn't call collapse/expand. Hmm.
Hey Caylan,
Is there a reason you're not just using the IGGridViewDataSourceHelpers? Why are you trying to rewrite the logic? You know you can just derive from them and extend functionality wherever you like, right?
Anyways, here is what the code does internally. It sounds like its doing something like you were doing. Although, i'm not sure why you're creating a custom section cell and putting logic in there. The IGGridViewSectionHeaderCell has the code needed already.
NSMutableArray* _collapsedSections;
-(BOOL)gridView:(IGGridView *)gridView sectionExpanded:(NSInteger)section
NSNumber* sec = @(section);
return ![_collapsedSections containsObject:sec];
-(void)gridView:(IGGridView *)gridView collapseSection:(NSInteger)section
if(![_collapsedSections containsObject:sec])
[_collapsedSections addObject:sec];
[gridView updateData];
-(void)gridView:(IGGridView *)gridView expandSection:(NSInteger)section
if([_collapsedSections containsObject:sec])
[_collapsedSections removeObject:sec];