What does nibNameOrNil mean?

The default init method signature for init -created view controllers is:

 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ } 

I saw that these are initialized with both values ​​given, just the name nib (with the package as zero) or just nil like both. Everything seems to work.

How UIViewController really handles self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; ? Is there a drawback to simply passing in nil for both values?

+6
source share
2 answers

If you pass nil as the nibName name, the method will look for a thread with the same file name as your view controller.

For example, if you have a view controller named MyViewController , it will look for the file MyViewController.xib nib.

If nib is not found, you need to override the loadView method to create and assign a UIView in the controller view.

 - (void)loadView { UIView *theView = [[UIView alloc] ... // Setup the main view self.view = theView; } 
+9
source

From docs :

nibName:

If you specify nil for the nibName parameter and you do not override the loadView method, the view controller will look for the nib file using other means. See NibName.

nibBundle:

Set to search for a nib file. This method first looks for the nib file in the project directories specific to the package language, and then the Resources directory. If nil, this method searches for the nib file in the main package.

+1
source

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


All Articles