Disable UITableView header floating

0x161

Floating headers enabled

If you’re using UITableView section headers for something more complicated than just displaying an alphabetical index of your table, then you may not like it’s default floating behavior.
  The section header view will always stick to the top of the table overlapping that portion of the section that remains visible.

There is no official way to disable this in any available version of iPhone SDK, so after several minutes of digging into UIKit framework I found these two private methods:

- (BOOL) allowsHeaderViewsToFloat;
- (BOOL) allowsFooterViewsToFloat;

The names suggest that all we need to do is subclass our UITableView and declare these two methods and explicitly return YES in them.

As it turns out—this hack works perfectly on every SDK version from 2.2.1 through 3.1, and there shouldn’t be any doubts about subclassing such simple and distinctly named private methods.

Floating headers disabled

2 Comments »

 
 

Leave a comment:

Tags: <a> <b> <cite> <code> <em> <i> <string> <strong>