I have an xib user interface which is appearing in the app, but the name of the file (ChatView.xib) doesn’t appear in the code anywhere. “ChatView” doesn’t appear anywhere, either (outside the name of the UIViewController subclass). So how does the app know to load the nib (xib) at all?
This had me stumped for a little while. Thanks for the insight, Ben:
Comment from Ben S. Stahlhood II
Time: October 26, 2009, 2:50 pm
The methods that Aaron discussed are good, but as of 3.0 you can also pass nil to both of the params of initWithNibName:bundle: or just do the alloc/init and it will look for a XIB with the same name as the UIViewController class. Of course, this can cause confusion if trying to still code for pre 3.0 and may not be as readable as actually specifying what is being loaded.
via http://weblog.bignerdranch.com/?p=129
Adversite here
Comments
Yup. Very convenient, potentially, though I don’t remember this being documented.
Interestingly, if the class name ends with the suffix “…Controller”, it’ll also look for a .xib name with that suffix omitted. So, in your example, if the class were called ChatViewController.h/.m … it’ll look for either ChatViewController.xib, or just ChatView.xib.
Again, this makes sense & it’s handy, but it’s not well-explained …
Leave A Comment