Objective c 在目标c中将一个xib文件的子视图添加到另一个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
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的深度副本。