Reputation: 737
My question is: i don't understand that we can create a ViewController with a nib file and we can create it without a nib file. i mean that : for example can anyone explan me the template, Navigation based application how it work, what is the first object instanciated ?
thanks for your answers
Upvotes: 2
Views: 649
Reputation: 6176
the only method to instantiate a UIViewControler is:
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
that mean you "normally" ask it to load a .nib file...
but you can also pass "nil" to both parameters:
myUIViewController = [[MyUIViewController alloc] initWithNibName:nil bundle:nil];
...if you want to load it directly and manage it by yourself. Generally you crate a subClass of UIViewController (MyUIViewController in my sample) and in its @implementation you implement the method loadView
where you need to create the view of your class
- (void)loadView{
UIView *aUIView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 480)];
self.view = aUIView;
aUIView.backgroundColor = [UIColor colorWithRed:.2 green:.3 blue:.5 alpha:1];
// aUIView... other properties to set if needed...
[aUIView release];
}
this way you can manage it all without a ".nib file", adding all objects and subView only via code...
Upvotes: 0
Reputation: 11914
The app's Info.plist file contains a property called "Main nib file base name" (NSMainNibFile). The nib file that is set here ("MainWindow.xib" by default) controls what will be loaded at startup.
If you don't have that set, and you want to launch an application without a default nib file, you need to pass in the name of your app delegate in your main.m file.
int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate");
http://blog.hplogsdon.com/ios-applications-without-any-nib-files/
Upvotes: 2