Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to make your own custom header row and put that as the first row of each section. Subclassing the <code>UITableView</code> or the headers that are already there will be a pain. Based on the way they work now, I am not sure you can easily get actions out of them. You could set up a cell to LOOK like a header, and setup the <code>tableView:didSelectRowAtIndexPath</code> to manually expand or collapse the section it is in.</p> <p>I'd store an array of booleans corresponding the the "expended" value of each of your sections. Then you could have the <code>tableView:didSelectRowAtIndexPath</code> on each of your custom header rows toggle this value and then reload that specific section.</p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { ///it's the first row of any section so it would be your custom section header ///put in your code to toggle your boolean value here mybooleans[indexPath.section] = !mybooleans[indexPath.section]; ///reload this section [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade]; } } </code></pre> <p>Then set <code>numberOfRowsInSection</code> to check the <code>mybooleans</code> value and return 1 if the section isn't expanded, or 1+ the number of items in the section if it is expanded.</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (mybooleans[section]) { ///we want the number of people plus the header cell return [self numberOfPeopleInGroup:section] + 1; } else { ///we just want the header cell return 1; } } </code></pre> <p>Also, you will need to update <code>cellForRowAtIndexPath</code> to return a custom header cell for the first row in any section.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload