Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just use a prototype cell as your section header and / or footer. </p> <ul> <li>add an extra cell and put your desired elements in it. </li> <li>set the identifier to something specific (in my case SectionHeader)</li> <li>implement the <code>tableView:viewForHeaderInSection:</code> method or the <code>tableView:viewForFooterInSection:</code> method</li> <li>use <code>[tableView dequeueReusableCellWithIdentifier:]</code> to get the header</li> <li>implement the <code>tableView:heightForHeaderInSection:</code> method.</li> </ul> <p><img src="https://i.stack.imgur.com/dKYjk.png" alt="(see screenhot)"></p> <pre class="lang-m prettyprint-override"><code>-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { static NSString *CellIdentifier = @"SectionHeader"; UITableViewCell *headerView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (headerView == nil){ [NSException raise:@"headerView == nil.." format:@"No cells with matching CellIdentifier loaded from your storyboard"]; } return headerView; } </code></pre> <p><strong>Edit:</strong> How to change the header title (commented question):</p> <ol> <li>Add a label to the header cell</li> <li>set the tag of the label to a specific number (e.g. 123)</li> <li>In your <code>tableView:viewForHeaderInSection:</code> method get the label by calling:</li> </ol> <pre class="lang-m prettyprint-override"><code> UILabel *label = (UILabel *)[headerView viewWithTag:123]; </code></pre> <ol start="4"> <li>Now you can use the label to set a new title:</li> </ol> <pre class="lang-m prettyprint-override"><code> [label setText:@"New Title"]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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