Avoid a UITableView headache

When using a custom section header view on a grouped UITableView, remember to implement the heightForHeaderInSection delegate method.

I initially left this out of a recent project because the documentation for the UITableView delegate method viewForHeaderInSection states:

The table view automatically adjusts the height of the section header to accommodate the returned view object.

What actually happened is that my header view was being clipped at the top and bottom, even though it was a UILabel which was the same font, weight and size of a standard section header (for the curious: I was attempting to change the text color).

A quick perusal of the documentation revealed the existence of a heightForHeaderInSection delegate method which made the view display as expected and there was much rejoicing.

UITableViewDelegate on Apple Developer Docs

One Comment on Avoid a UITableView headache

You can track this conversation through its atom feed.

  1. sanjay on December 16th, 2008 at 7:38 am

    No man we can adjust the things as we want , we can set every thing.
    read the doc carefully you make it easily.

Leave a Comment

(required) (required, but not published) (optional)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>