我一直在查看示例代码,有时 Apple 将 xib 文件命名为 ClassNameView
,有时命名为 ClassNameViewController
。 ClassName
始终是 UIViewController
或 UITableViewController
,这让我想知道在命名 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:
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.
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/