Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何将故事板中定义的视图用于viewForHeaderInSection?_Objective C_Uitableview_Uiview_Ios7_Uistoryboard - Fatal编程技术网

Objective c 如何将故事板中定义的视图用于viewForHeaderInSection?

Objective c 如何将故事板中定义的视图用于viewForHeaderInSection?,objective-c,uitableview,uiview,ios7,uistoryboard,Objective C,Uitableview,Uiview,Ios7,Uistoryboard,更新:我用一个nib文件完成了这项工作。参见Josh Justice关于如何设置头视图的nib(文件->新文件->用户界面->视图)过程的回答。这并不简单: 我试图在我的故事板中定义一个UIView,并将其用作我的UITableView标题的布局。我曾作为一个向导,但似乎无法让它工作(ios7)。我试过使用帖子中显示的UIImageView,以及常规的UIView,但没有成功。有一件事我不明白,我可以创建一个新的UIView,如下所示,并且可以很容易地设置背景颜色,但是如果我使用标签从情节提要

更新:我用一个nib文件完成了这项工作。参见Josh Justice关于如何设置头视图的nib(文件->新文件->用户界面->视图)过程的回答。这并不简单:


我试图在我的故事板中定义一个
UIView
,并将其用作我的
UITableView
标题的布局。我曾作为一个向导,但似乎无法让它工作(ios7)。我试过使用帖子中显示的
UIImageView
,以及常规的
UIView
,但没有成功。有一件事我不明白,我可以创建一个新的
UIView
,如下所示,并且可以很容易地设置背景颜色,但是如果我使用标签从情节提要中加载视图,我似乎无法更改背景,它只会显示为灰色。我做错了什么?!我想我可以在代码中创建整个标题,但这里似乎缺少了一些东西

- (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);
}


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

必须通过编程方式或在单独的nib文件中创建视图来完成您试图执行的操作