why bundle is nil, after initWithNibName? objective-c
i was wondering : why do we set "bundle" to "nil", when we alloc-init a viewController?
example :
MyViewController *viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
Th开发者_如何学Canks
Paul
If bundle is nil, this method looks for the nib file in the main bundle. So it's the same as to pass [NSBundle mainBundle]
See UIViewController class reference
As it is says in the documentation:
Parameter - nibBundle
The bundle in which to search for the nib file. This method looks for the nib file in the bundle's language-specific project directories first, followed by the Resources directory. If nil, this method looks for the nib file in the main bundle.
Since your nib is in the main bundle you can just set that parameter to nil. If it was not you would have to tell it where to search.
Using nil
there is equivalent to using [NSBundle mainBundle]
. Read the documentation.
In general, if you have any question about a method in an Apple-provided class, first read the official documentation before coming here :)
精彩评论