【问题标题】:How to make a view controller without a xib or a storyboard vc identifier?如何制作没有 xib 或故事板 vc 标识符的视图控制器?
【发布时间】:2016-01-10 08:36:41
【问题描述】:

我想知道如何在不使用xibstoryboard 的情况下制作viewcontroller。所以在这种情况下,我会得到viewcontroller

   PopupViewController* vc = [[PopupViewController alloc] init];
    [self addChildViewController:vc];
    [self.view addSubview:vc.view];
    [vc didMoveToParentViewController:self];

我知道它必须与重写 init 方法有关,因为我们没有使用 initWithCoder

我知道我必须创建一个视图并将其设置为 PopupViewController 的 self.view,但我想知道我该怎么做。

编辑:是的,创建xib file 或在storyboard 中添加view controller 可能更容易,这是为了深入了解view controllers 的工作原理。

【问题讨论】:

标签: ios objective-c uikit


【解决方案1】:

初始化视图的最佳位置是在PopupViewControllerloadView 方法中。比如:

- (void)loadView {
   self.view = [MyViewClass new];
}

然后,在MyViewClass initWithFrame: 方法中构建所有子视图并为其设置约束。如果您没有使用约束,请覆盖 layoutSubviews 方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    • 2015-02-21
    • 2021-08-05
    • 1970-01-01
    相关资源
    最近更新 更多