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
630
Expandable sections when using IGGridViewDataSource
posted

I implemented gridView:cellForSectionHeader so that I could set .expandable=YES on an IGGridViewSectionHeaderCell. When I click on the section header, I see that gridView:collapseSection and gridView:expandSection are called, and same with gridView:sectionExpanded, but I’m not sure what to do in those to get the sections to expand/collapse when I click on the section headers. Any help is appreciated.

Parents
  • 40030
    Verified Answer
    Offline posted

    Hi Jeff, 

    Just as a quick side note: you only need to implement these methods if you're implementing the dataSource protocol yourself. If you happen to use our IGGridViewDataSourceHelper classes, you get this functionality for free. 

    And just in case you haven't seen the topic, there is a quick overview right here:(however, i'm guessing you've already seen this)

    http://help.infragistics.com/iOS/2014.1/?page=IGGridView_Configuring_Expandable_Sections.html

    As for an example of the implementation, here is what the DataSource helper actually does: 

    -(IGGridViewSectionCell *)gridView:(IGGridView *)gridView cellForSectionHeader:(NSInteger)section
    {
       IGGridViewSectionHeaderCell* cell = [IGGridViewSectionHeaderCell gridView:gridView cellForSectionHeader:section];
       cell.expandable = YES;// self.allowSectionExpansion;

       return cell;

    }

    -(BOOL)gridView:(IGGridView *)gridView sectionExpanded:(NSInteger)section
    {
       NSNumber* sec = [NSNumber numberWithInteger:section];
       return ![_collapsedSections containsObject:sec];
    }

    -(void)gridView:(IGGridView *)gridView collapseSection:(NSInteger)section
    {
       NSNumber* sec = [NSNumber numberWithInteger:section];
       if(![_collapsedSections containsObject:sec])
       {
          [_collapsedSections addObject:sec];
          [gridView updateData];
       }
    }

    -(void)gridView:(IGGridView *)gridView expandSection:(NSInteger)section
    {
       NSNumber* sec = [NSNumber numberWithInteger:section];
       if([_collapsedSections containsObject:sec])
       {
          [_collapsedSections removeObject:sec];
          [gridView updateData];
       }
    }

    The _collaspedSections field mentioned in the snippet is simply an NSMutableArray. 

    Essentially, all you're doing is storing off the state of whether a particular section is expanded or collapsed. 

    Hope this helps!

    -SteveZ


Reply Children