tags:

views:

51

answers:

2
RootViewController *rvController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

sometimes i see it use nil ,i dont know what exactly it use for?

+1  A: 

http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSBundle_Class/Reference/Reference.html#//apple_ref/doc/uid/20000214-BCIDFECI

This method allocates and initializes a bundle object if one doesn’t already exist. The new object corresponds to the directory where the application executable is located. Be sure to check the return value to make sure you have a valid bundle. This method may return a valid bundle object even for unbundled applications.

In general, the main bundle corresponds to an application file package or application wrapper: a directory that bears the name of the application and is marked by a “.app” extension.

According to the docs, initWithNibName:bundle: just calls this when you pass in nil.

http://developer.apple.com/iphone/library/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW15

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.

So, they are equivalent

Lou Franco
thank you for you advise,Lou Franco
RAGOpoR
+1  A: 

Here is the exact explanation for that:

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.

I think [NSBundle mainBundle] doesn't do anything different than you put nil. However, if you want to do internationalization and localization, you can use them

More details here

vodkhang
thank you for you advise,vodkhang
RAGOpoR