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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With