When I create a uiviewcontroller from the “new file…” wizard with “create xib file” option, I can load it by just SomeViewController *view = [[SomeViewController alloc] init]. But when I rename the xib file name, this code stops working, even though the file owner in the xib is still the right view controller.
I found that I can only get the view up by calling initWithNib. I am just wondering what was linking the xib with the view controller behind the scene? Can I still use init to get the xib loaded after renaming the file?
Regards
Leo
You can, but (IMO) you shouldn’t. The designated initializer for UIViewController is
-initWithNibName:bundle:. You might implement an-initmethod in your own view controller that calls[super initWithNibName:nil bundle:nil], but I think the code is clearer if you stick with the same name.Also, make sure you read the documentation for UIViewController, particularly the discussion, which says:
This is why the view controller will load a .xib file that has the same name as the view controller’s class (or the name returned by the
-nibNamemethod, as explaind a little further on in the docs).In short, UIViewController is functioning exactly as documented.