1
votes

I created a new window based applications. Immediately i created a class as a subclass of ViewController and in the appdelegate didFinishLaunchingWithOptions method i've added the following code

TestView myView = [[TestView alloc] initWithNibName:nil bundle:nil];

[self.window makeKeyAndVisible]; [self.window addSubview:mainMenu.view];

[mainMenu release]

However, despite this it still initializes the nib. If i placed a button in TestView.xib it shouldn't technically show it right? I initialized TestView without a nib? Why does it show up?

2

2 Answers

0
votes

If you pass nil to -initWithNibName:bundle:, it will attempt to load a nib from the main bundle that has a filename that matches the name of the subclass, or the name of the subclass without the "Controller" suffix.

0
votes

If you dont want it from a nib you should not init it in this way, it will still search for a xib that matches the class name exactly.

From the apple documentation found here: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

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.