Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.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 在目标c中将一个xib文件的子视图添加到另一个xib文件_Objective C_Xcode4_Subview - Fatal编程技术网

Objective c 在目标c中将一个xib文件的子视图添加到另一个xib文件

Objective c 在目标c中将一个xib文件的子视图添加到另一个xib文件,objective-c,xcode4,subview,Objective C,Xcode4,Subview,我的一个xib文件中有一个标题视图。我想在其他一些视图中重用此标题视图作为标题。我可以将其添加为子视图吗?有人尝试过吗?我尝试使用以下代码,但发现不起作用 claimedPageTemplateone * claimedtemplateone=[[claimedPageTemplateone alloc]initWithNibName:@"claimedPageTemplateone" bundle:[NSBundle mainBundle]]; claimedtemplateone.del

我的一个xib文件中有一个标题视图。我想在其他一些视图中重用此标题视图作为标题。我可以将其添加为子视图吗?有人尝试过吗?我尝试使用以下代码,但发现不起作用

 claimedPageTemplateone *  claimedtemplateone=[[claimedPageTemplateone alloc]initWithNibName:@"claimedPageTemplateone" bundle:[NSBundle mainBundle]];
claimedtemplateone.delegate=self;
[ headerView addSubview:claimedtemplateone.background ];
其中“claimedPageTemplateone”是具有标题的视图,“background”是我必须重用的合成标题视图,“headerView”是我需要添加子视图的视图。
提前感谢。

尝试从一个xib复制您的
UIView
,然后在Interface Builder中粘贴到另一个xib。

尝试一下,它可能会起作用:

claimedPageTemplateone *  claimedtemplateone = [[claimedPageTemplateone alloc]initWithNibName:@"claimedPageTemplateone" bundle:[NSBundle mainBundle]];
claimedtemplateone.delegate=self;

claimedtemplateone.background = [[UIView alloc] initWithNibName:@"background nib name" bundle:[NSBunble mainBundle]];

[ headerView addSubview: claimedtemplateone.background];

标题中的所有值也应该显示在此视图中。因此,我正在寻找一种方法来重用标题本身。好的,您不能再次使用UIView,因为您不能更改其superview。但您可以制作UIView的深度副本。