0

更新:我最终使用了一个 nib 文件。有关如何为标题视图设置笔尖(文件 -> 新文件 -> 用户界面 -> 视图)的过程,请参阅 Josh Justice 的回答。这并不简单:已加载 nib 但未设置视图出口 - InterfaceBuilder 的新功能


我正在尝试UIView在我的 Storyboard 中定义 a 并将其用作UITableView标题的布局。我将此帖子用作指南,但似乎无法使其正常工作(ios7)。我试过使用UIImageView如帖子中所示,以及常规UIView但没有运气。我不明白的一件事是我可以创建一个新的UIView,如下所示,并足够轻松地设置背景颜色,但是如果我使用标签从情节提要中加载视图,我似乎无法更改背景和它只显示为灰色。我在这里做错了什么?!我想我可以在代码中创建整个 Header 但似乎我在这里缺少一些东西。

在此处输入图像描述

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   // doing it this way, the header stays positioned
   // and visible no matter where the table is scrolled
   // UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];

   // pulling the view out of the storyboard doesn't seem to work
   // can't change bgcolor on this view.. 
   UIView *v = [[UIView alloc] viewWithTag:200];

   // this only changes the background color when the view is created
   // with initWithFrame.. above. Otherwise it's just gray.
   [v setBackgroundColor:[UIColor colorWithRed:0 green:.7 blue:.9 alpha:1]];
   return (v);
}
4

1 回答 1

0

该帖子是针对表格视图的标题,而不是针对表格视图的每个部分。

您要做的事情必须通过以编程方式或在单独的 nib 文件中创建视图来完成。

于 2013-10-10T17:46:39.540 回答