Under the documentation for UIViewController -> nibName property it says:
This property contains the value specified at initialization time to the initWithNibName:bundle: method. The value of this property may be nil.
If you use a nib file to store your view controller’s view, it is recommended that you specify that nib file explicitly when initializing your view controller. However, if you do not specify a nib name, and do not override the loadView method in your custom subclass, the vie开发者_如何学JAVAw controller searches for a nib file using other means. Specifically, it looks for a nib file with an appropriate name (without the .nib extension) and loads that nib file whenever its view is requested. 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.
My question is, how does the class know its own filename?
I think in the framework they are using there own own API...
NSString *string = NSStringFromClass([self class]);
So they can get the classname...
As in the document they are searching for the viewController class name ends with the word "Controller".
精彩评论