iphone - xib 的命名约定

标签 iphone ios cocoa-touch naming-conventions xib

我一直在查看示例代码,有时 Apple 将 xib 文件命名为 ClassNameView,有时命名为 ClassNameViewControllerClassName 始终是 UIViewControllerUITableViewController,这让我想知道在命名 xib 时应使用什么约定。我认为 View 并不是真正的 ViewController,但对 约定是什么感到好奇,或者至少对 xibs 的命名约定是什么感到好奇。

最佳答案

CocoaTouch 支持这两种约定,优先使用较短形式的 ClassNameView,根据下面描述的未指定 nib 名称时的 nib 加载过程(来自 the UIViewController documentation, under nibName):

Specifically, it looks (in order) for a nib file with one of the following names:

  1. If the view controller class name ends with the word “Controller”, as in MyViewController, it looks for a nib file whose name matches the class name without the word “Controller”, as in MyView.nib.

  2. It looks for a nib file whose name matches the name of the view controller class. For example, if the class name is MyViewController, it looks for a MyViewController.nib file.

所以正如其他人所说,这是一个偏好问题!我个人喜欢较短的版本,但可以看出两者的逻辑。

关于iphone - xib 的命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/960042/

相关文章:

ios - 在 viewDidLoad 中运行 MPMoviePlayerController 的奇怪行为

iphone - 无法加载名为

iphone - 如何关闭回车键上的数字键盘

iphone - 打开 xcode 项目时遇到奇怪的问题

iphone - 第 5 代设备上更大的启动图像

ios - ios 5.1 中的自动刷新 uiviewcontroller

ios - 用户按下了 UIAlertView 上的哪个按钮?

iphone - 我正在比较指针和整数

ios - 如何确定View的背景颜色?

ios - 无法将类型 '(Int) -> Void' 的值转换为预期的参数类型 '(Any) -> Void'