在UIViewController中包含的UIView中调用不同的UIView .xib

时间:2015-07-01 15:28:12

标签: ios objective-c iphone uiview uiviewcontroller

我在UIViewController(onboardingViewController)中有一个UIView(包含View)。

我有3个xib是UIViews,我想依次将每个xib UIView调用到放在onboardingViewController中的containsView。

所以我的问题是,如何引用每个xib来调用在containsView中显示它?

我尝试将视图放在数组中,然后将它们添加到containsView的子视图中,但是当我运行应用程序时,我无法查看它们。

1 个答案:

答案 0 :(得分:0)

听起来您首先要以编程方式加载xib文件中的视图,然后将其添加到containerView

// Load the UIViews from your Xib files
UIView *view1 = [[[NSBundle mainBundle] loadNibNamed:@"MyView1" owner:self options:nil] objectAtIndex:0];
UIView *view2 = [[[NSBundle mainBundle] loadNibNamed:@"MyView2" owner:self options:nil] objectAtIndex:0];
UIView *view3 = [[[NSBundle mainBundle] loadNibNamed:@"MyView3" owner:self options:nil] objectAtIndex:0];

// Now that you have references to your xibs, add them as subviews to your containingView
[containingView addSubview:view1];
[containingView bringSubviewToFront:view1];

// repeat as you need to load views 2 and 3