How does remote xib load?

I created the class 'abc', which is a subclass of UIViewController. During its creation, I pressed the button to create xib for it automatically. Now xcode creates 3 files for me 1. abc.h 2. abc.m 3. abc.xib.

Now when I create an object of class abc, for example abc * a = [abc alloc];

Even when I do not initialize an object named beginwithNibName and do not use it, it loads the xib file. So how is this xib file associated with the abc object. And even if I deleted abc.xib, then it will also download this xib file. I could not understand where it was loading the xib file from if it was not present in the project space. Where is the xib and controller association stored?

Thanks in advance.

+6
source share
2 answers

What happens is that the default implementation of initWithNibName:bundle: searches the main Bundle for the Nib file with the same name as the View Controller class. This happens if you automatically choose the option to create Nib or not. See the UIViewController documentation (part of a discussion of initWithNibName:bundle: .

Now the initWithNibName:bundle: method is the default initializer of the UIViewController, which means that even if you do not use it directly (say that you use init ), it will still be called under the hood.

Finally, even if you deleted the Nib file from Xcode, for some reason (not sure why) it is not deleted from the main package (at least in the simulator). Even if you clean and build a project, it remains there. The solution I use to completely get rid of the Nib file is to remove the application from the simulator, and then clean and build it again.

Hope this helps!

+8
source

xib is probably still in your compiled area, so you need to do a cleanup to get rid of it completely. (Product → Clear). The default init method for UIViewControllers will automatically search for xib with the same name, so it still allocates that xib. As soon as you clean it, it will stop.

Link: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/initWithNibName:bundle :

Pay attention to this part: if you specify nil for the nibName parameter, you must either override the loadView method, or create your views there, or you must provide the nib file in your package whose name (without the .nib extension) matches the name of your controller class kind of. (In this latter case, the class name becomes the name stored in the nibName property.) If you do nothing, the view controller cannot load its view.

+1
source

Source: https://habr.com/ru/post/905890/


All Articles