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

Calling different UIView .xibs in a UIView contained in a UIViewController

我在 UIViewController (onboardingViewController) 中有一个 UIView (containingView)。

我有 3 个 xib,它们是 UIView,我想按顺序将每个 xib UIView 调用到放置在 onboardingViewController 中的 containingView。

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

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

听起来您首先想以编程方式从您的 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