Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7, table header view does not float

I have a UITableView set up on my app, which runs on iOS 7. I has one section and it loads images into custom cells and it scrolls under the navigation bar as well, which is translucent. So initially, the content is below the navbar and it scrolls under the navbar as we scroll down to view more images. For this I have set an initial contentInset of UIEdgeInsetsMake(40, 0, 0, 0). Now sometimes, I need a small header view on my table to indicate types of images on my table. So I have used the following code:

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return 30.0;

}

-(UIView*) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    TableSectionHeader *header=[[[NSBundle mainBundle] loadNibNamed:@"TableSectionHeader" owner:self options:nil] objectAtIndex:0];

    [header.title setText:[NSString stringWithFormat:@"Type: %@", self.imageType]];

    return head;
}

Where TableSectionHeader is custom view I have created for this purpose. Now ideally, the header must float or "stick" either just below the navbar or at the top of the table (which is under the navbar). But in this case, it just rolls off screen. I want the header to stick right under the navbar. Does anyone know how I can achieve this?

like image 492
Rameez Hussain Avatar asked Dec 12 '13 21:12

Rameez Hussain


1 Answers

Change the table view's style from Grouped to Plain.

From the official documentation, regarding the Plain table view style:

A plain table view can have one or more sections, sections can have one or more rows, and each section can have its own header or footer title. (A header or footer may also have a custom view, for instance one containing an image). When the user scrolls through a section with many rows, the header of the section floats to the top of the table view and the footer of the section floats to the bottom.

like image 141
nhgrif Avatar answered Nov 08 '22 04:11

nhgrif