为什么 Apple 建议以编程方式创建模态导航控制器?
“以模态方式呈现导航控制器时,以编程方式创建和配置导航控制器对象通常更简单。虽然您也可以使用 Interface Builder 来执行此操作,但通常不建议这样做。” 事实上,因为我的导航控制器很简单,我宁愿在IB中自定义视图!
"When presenting a navigation controller modally, it is often simpler to create and configure your navigation controller object programmatically. Although you could also use Interface Builder to do so, doing so is generally not recommended."
If fact, because my navigation controller is simple, I would rather customise the view in IB!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我不知道确切的原因,但这是我的尝试:
以编程方式创建控制器时,您只需要几行代码,事实上,在大多数情况下,这可能真的很少:创建、设置根控制器、呈现和发布。替代方案很快就能枚举出来:
,因为替代方案只需几行代码设置,加载 nib 文件的开销实际上并不是非常便宜,并不值得额外的舒适。如果您正在进行大量设置,那么无论如何,无论是从 nib 加载还是在代码中创建,这都会进入自定义类。
只是我的想法...
While I don't know the exact reason, this is my shot at it:
When creating the controller programmatically, you need only a few lines of code, in fact, in most cases this might be really few: creating, setting the root controller, presenting and releasing. The alternatives are quickly enumerable:
Now, given that the alternative is only a few lines setup of code, the overhead of loading a nib file, which is in fact not extremely cheap, isn't really worth the additional comfort. If you are doing a lot of setup then this would go into a custom class anyways, no matter whether loading from nib or creating in code.
Just my thoughts...