Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple sections to be closed programmatically #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mmmilo
Copy link

@mmmilo mmmilo commented Feb 15, 2013

I'm looking to be able to close sections programmatically.

Use case: You have 3 sections, but only one should be open at a time. Let's say section 0 is already open. If you select section 2, section 0 should automatically be closed.

The issue:
didSelectTitleCell uses [self.tableView indexPathForSelectedRow];. When you are programmatically closing a section, the index path will be nil.

Solving the issue:
Added an extra function and variable that lets you specify which section is the one being animated.

Example usage:
In your "controlling" viewController:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  GCRetractableSectionController* sectionController = [self.retractableControllers objectAtIndex:indexPath.section];
  [sectionController didSelectCellAtRow:indexPath.row];

  // close the previous open section
  if (indexPath.section != activeSection) {
    GCRetractableSectionController* sectionController = [self.retractableControllers objectAtIndex:activeSection];
    if (sectionController.isOpen) {
      [sectionController didSelectCellAtRow:0 inSection:activeSection];
    }
    activeSection = indexPath.section;
  }

}

@gcamp
Copy link
Owner

gcamp commented Feb 16, 2013

Valid concern, I'm not sure this is the best way to do it however. Hmm... Basically I don't like the idea of an other variable just for that.

@ebrahimElgeded
Copy link

so how can i programicaly close any previous opened section ? i need only one section to be opened ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants