【问题标题】:How to use a view defined in a Storyboard for viewForHeaderInSection?如何将 Storyboard 中定义的视图用于 viewForHeaderInSection?
【发布时间】:2013-10-18 14:45:45
【问题描述】:

更新:我最终使用了一个 nib 文件。有关如何为标题视图设置笔尖(文件->新文件->用户界面->视图)的过程,请参见 Josh Justice 的回答。这并不简单:Loaded nib but the view outlet was not set - new to InterfaceBuilder


我正在尝试在我的 Storyboard 中定义一个 UIView 并将其用作我的 UITableView 标题的布局。我使用this post 作为指导,但似乎无法让它工作(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);
}

【问题讨论】:

    标签: objective-c uitableview uiview ios7 uistoryboard


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-04-14
      • 2015-09-15
      • 1970-01-01
      • 2012-03-18
      • 2015-02-20
      • 2015-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多