UIView没有在两个标题视图中显示 [英] UIView not showing in both header views
问题描述
我正在开发一个 iPad
应用程序。出于某些原因,我需要在同一个视图控制器中显示两个tableviews
。我在 xib
中创建了 UIView
并连接了一个 outlet
到那个视图控制器
。我需要在这两个tableviews中将该视图显示为 tableHeaderView
。当我尝试将该视图分配给两个标题视图
时,它仅显示在第二个表视图
中。我希望在那里是该视图的单个实例。因此它仅在我最后指定的视图中显示。我怎么能克服这个?任何帮助,将不胜感激。
I am developing an iPad
application. For some reasons, I need to show a two tableviews
in the same view controller. I have created a UIView
in a xib
and connected a outlet
to that view controller
. I need to show that view in those two tableviews as a tableHeaderView
. When I try to assign that view to both header views
, it is showing only in the second tableview
.I hope there is a single instance for that view. So it is showing on only in the view, which I assigned last. How could I overcome this?? Any help would be appreciated.
这是我的代码。
[energyTableView setTableHeaderView:tableHeader];
[maintenanceTableView setTableHeaderView:tableHeader];
@CodeBySteveZ
@CodeBySteveZ
正如他所说,我创建了一个xib并尝试过。我仍然无法得到解决方案。我做错了吗?这就是我尝试的方式。
As he said, I created an xib and tried. And still I can't get the solution. Am I doing anything wrong??here it is how I tried.
NSArray *topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"tableHeaderCell" owner:nil options:nil];
[energyTableView setTableHeaderView:[topLevelObjects objectAtIndex:0]];
[maintenanceTableView setTableHeaderView:[topLevelObjects objectAtIndex:0]];
我认为这也和以前一样。
I think this is also a same thing as I did before.
推荐答案
您必须创建tableHeader的另一个实例。 UIView一次只能存在于一个可视子树中。使用IB,您可以复制元素并创建它的2个实例。或者,如果您使用该元素创建单独的xib,则可以通过代码将该特定xib加载两次,每个表头一次。
You'll have to create another instance of the tableHeader. A UIView can only live in one visual sub-tree at a time. Using IB you could copy the element and create 2 instances of it. Or if you create a separate xib with that just element you could load that particular xib twice via code, once for each table header.
这篇关于UIView没有在两个标题视图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!