我对界面生成器感到非常沮丧,我正尝试在代码中创建我的 View Controller 。我设法设置了窗口并创建了一个导航 Controller 并将其添加为 Root View Controller ...
我不太确定应该从哪里开始添加按钮并设置它们的目标......
我应该将执行此操作的代码放在我的 UIViewController 子类中还是放在其他更好的地方?
此外,一旦我完成了该操作...放置自动布局约束的最佳位置是什么?
如有任何帮助,我们将不胜感激。
最佳答案
每个 View Controller 子类都应该创建和释放自己的按钮、控件、 subview 等。
您可以通过覆盖此 UIViewController
方法来完成所有 View Controller 设置
- (void)viewDidLoad
{
[super viewDidLoad];
...
UIButton* newButton = [UIButton buttonWithType:...];
// other button config (including constraints)
[self addSubview:newButton];
...
// create and setup other subviews
}
关于ios - 放置 UIViewController 设置代码的最佳位置在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18392156/