initWithNibName on iOS is clever: it does things like automatically load different NIB for iPad instead of iPhone (although lots of people don't know this - it IS NOT DOCUMENTED in UIViewController.initWithNibName!).
But what else can it do? The only Apple docs I've found for this explain that:
But there's no link to the rules for image matching, and I can't find any explicit docs for either :(.
Rules might include: "you get a different NIB for retina if you put @2x on the end of the filename" (I have no idea if this works).
What I'm really looking for is a list of what rules ARE used. It would save a lot of hardcoding - repeated in almost every single app I write - if I could make more use of their intelligent name matching (e.g. if they have a "load landscape nib vs. load portrait nib")
To answer your (main) question, these are the rules for filename matching in initWithNibName
:
...However, if you do not specify a nib name, and do not override the loadView method in your custom subclass, the view 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.
From UIViewController's documentation under nibName
But there is more... Actually the NSBundle
have some pretty smart rules for locating resources inside it. Here is the documentation page describing these rules
(see: Device-Specific Resources in iOS).
Which brings us to this page that describes all the modifiers (and the basic pattern) that can be applied to bundle resources (this I believe is the link you're mentioning regarding image filename matching).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With