何时使用InterfaceBuilder构建视图? [英] When to use InterfaceBuilder to build views?

查看:73
本文介绍了何时使用InterfaceBuilder构建视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过广泛的在线文档和开发中心的各种代码示例,我感到很困惑。 Apple建议在创建视图时始终使用IB,然而,在许多代码示例中,视图完全由代码创建(在viewController的loadView方法中初始化)。
是否有关于何时应使用IB而不是代码来创建观点的最佳实践?

Going thru both the extensive online documentation AND the various code samples in the dev center I am perplexed. Apple's recommends to ALWAYS use IB when creating your views, and yet, in many of the code samples, views are created entirely in code (initialized in the loadView method of the viewController). Is there a 'best practice' as to when you should use IB as opposed to code to create your views?

推荐答案

没有严格的规则,但总的来说,视图越复杂,我就越倾向于使用IB。像NavigationView中的TableView这样非常简单的东西几乎总是在代码中。更复杂的布局,如具有数十个输出标签的详细视图,将倾向于在IB中布局。

There are no hard and fast rules, but in general, the more complex a view is, the more I'll tend to use IB. Very simple things like a TableView in a NavigationView will nearly always be in code. More complex layouts like a detail view with dozens of output labels will tend to be laid out in IB.

这就是说,如果由于某种原因我不想在最终产品中包含XIB,例如如果这是用于静态库,我将开始使用IB,然后使用 NIB代码转换器。

That said, if for some reason I don't want to include the XIB in the final product, such as if this is for a static library, I'll start with IB and then use a NIB to code converter.

这篇关于何时使用InterfaceBuilder构建视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆