iOS 7,表头视图不浮动 [英] iOS 7, table header view does not float
问题描述
我的应用程序上设置了 UITableView
,它在iOS 7上运行。我有一个部分,它将图像加载到自定义单元格中,并在<$下滚动c $ c>导航栏也是半透明的。所以最初,内容低于导航栏
,当我们向下滚动查看更多图像时,它会在导航栏
下滚动。为此我设置了的初始
。现在有时,我需要在我的桌子上有一个小的标题视图来指示我桌子上的图像类型。所以我使用了以下代码: contentInset
UIEdgeInsetsMake(40,0,0,0)
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;
}
其中 TableSectionHeader
是我为此创建的自定义视图。理想情况下,标题必须浮动或粘贴在导航栏
下方或表格顶部(位于导航栏下方)。但在这种情况下,它只是滚出屏幕。我希望标题直接位于导航栏
下。有谁知道我怎么做到这一点?
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?
推荐答案
从 Grouped $更改表格视图的样式c $ c>到
普通
。
来自官方文档,关于 Plain
表视图样式:
From the official documentation, regarding the Plain
table view style:
普通表视图可以有一个或多个部分,部分可以有
一行或多行,每个部分都有自己的部分页眉或页脚
标题。 (页眉或页脚也可以有自定义视图,例如
包含图像的视图)。 当用户滚动浏览
多行的部分时,该部分的标题将浮动到表
视图的顶部,该部分的页脚将浮动到底部。
这篇关于iOS 7,表头视图不浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!