如何使视图控制器没有xib或故事板vc标识符?
我想知道如何在不使用xib
或storyboard
的情况下xib
。 所以在这种情况下,我会得到这样的viewcontroller
PopupViewController* vc = [[PopupViewController alloc] init]; [self addChildViewController:vc]; [self.view addSubview:vc.view]; [vc didMoveToParentViewController:self];
我知道它必须重写init方法,因为我们不使用initWithCoder
?
我知道我必须创build一个视图,并将其设置为PopupViewController
,但我想知道如何做到这一点。
编辑:是的,只是制作一个xib file
或添加view controller
到storyboard
可能会更容易,这是深入了解如何view controllers
工作。
启动视图的最佳位置是在PopupViewController
的loadView
方法中。 就像是:
- (void)loadView { self.view = [MyViewClass new]; }
然后,在MyViewClass
initWithFrame:
方法build立所有的子视图,并为其设置约束。 如果您不使用约束,请覆盖layoutSubviews
方法。