【问题标题】:Add UIViews as subviews to UIViewController [closed]将 UIViews 作为子视图添加到 UIViewController [关闭]
【发布时间】:2014-05-28 17:41:15
【问题描述】:

我用一个 Xib 文件创建了 2 个 UIView。我需要如何将它们添加到UIViewController

【问题讨论】:

标签: ios uiview uiviewcontroller


【解决方案1】:

在 View Controller 中导入 firstView 并执行以下操作:

firstView *firstView = [[firstView alloc] init];

或者这个:

UIView *firstView = [[[NSBundle mainBundle] loadNibNamed:@"firstView" owner:self options:nil] firstObject];

然后,这个:

[self.view addSubview:firstView];

如果你需要访问firstView的子视图,你需要在firstView类中为你要访问的子视图设置一个标签:

[subview setTag:100];

然后您在 View Controller 中检索该视图,如下所示:

UIView *subView = [firstView viewWithTag:100];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 2011-06-21
    • 2010-12-01
    • 2017-01-26
    • 1970-01-01
    相关资源
    最近更新 更多