I have created a class 'abc' which a subclass of UIViewController. At the time of creating it i clicked the option for creating an xib for it automaticaly. Now the xcode creates 3 files for me 1. abc.h 2. abc.m 3. abc.xib.
Now whenever i create an object of abc class like abc *a=[abc alloc];
Even when i am not initialising the object with initiwithNibName and using it, it is loading the xib file. So how this xib file got associated with the abc object. And even if i deleted the abc.xib, then also it loads that xib file. I couldnt understand from where it is loading the xib file, if it it not present in the project space. And where the association of xib and controller is stored?
Thanks in advance.
What's going on is that the default implementation of initWithNibName:bundle:
searches the Main Bundle for a Nib file that has the same name as your View Controller class. This happens whether you select the option for creating the Nib automatically or not. See UIViewController documentation (the discussion portion of initWithNibName:bundle:
).
Now the initWithNibName:bundle:
method is UIViewController's default initializer, which means that even if you don't use it directly (say that you use init
instead) it will get called under the hood anyway.
Finally, even if you delete the Nib file from XCode, for some reason (not sure why) it doesn't get deleted from the Main Bundle (at least in the simulator). Even if you clean & build the project it stays there. The solution I use to get completely rid of the Nib file is to delete the App from the simulator, then clean & build again.
Hope this helps!
The xib is probably still in your compiled area, so you need to perform a clean to get rid of it fully. (Product >> Clean). The default init method of UIViewControllers will automatically look for a xib of the same name, which is why it's still allocating that xib. Once you clean it will stop.
Reference: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/initWithNibName:bundle:
Note this part: If you specify nil for the nibName parameter, you must either override the loadView method and create your views there or you must provide a nib file in your bundle whose name (without the .nib extension) matches the name of your view controller class. (In this latter case, the class name becomes the name stored in the nibName property.) If you do none of these, the view controller will be unable to load its view.
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