Here's how I do it. From the start.
1.Create a new project, choose a Window-based Application. For example I named my project as Test.
//You will then have only two files, your TestAppDelegate.h and .m.
2.On your .h, create an "IBOutlet UINavigationController" like this:
Code:
#import <UIKit/UIKit.h>
@interface TestAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
IBOutlet UINavigationController *xNavi;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UINavigationController *xNavi;
@end
3.On your .m, synthesize and release the UINavigationController.
Code:
#import "TestAppDelegate.h"
@implementation TestAppDelegate
@synthesize window;
@synthesize xNavi;
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window makeKeyAndVisible];
}
- (void)dealloc
{
[xNavi release];
[window release];
[super dealloc];
}
@end
***Very Important: Always save the changes you make. Like for this, you may not be able to link your UINavigationController to your AppDelegate if you didn't save the changes above before moving to the next step.
4.Now, open your MainWindow.xib, Open Tools->Library. Or simply press command+shift+L.
5.From the library, drag a Navigation Controller to your MainWindow.xib. It should be together with your File's Owner, First Responder, Test App Delegate and Window.
6.Select your newly added UINavigation Controller and Open Tools->Connection Inspecter (command+2).
7.Connect Your Referncing Outlets to Test App Delegate. The xNavi should appear there, select it.
8.Save everything and try to run it.
9.If you see a white screen, that is because we are still seeing the window. What we need to do is to add xNavi to window, like this:
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window addSubview:self.xNavi.view];
[window makeKeyAndVisible];
}
10.Try running it now. The only thing left is to place a View on the View controller of your Navigation Controller.
11.This is how I do it so that it would not be a tableView Controller.
12.Add a new file on your classes.
13.Select "UIViewController subclass".
14.Check on "With XIB for user interface".
15.Click next, then name it whatever you like, then Finish.
16.You will now have 5 files under your classes, appdelegate.m and .h, the three new files .m, .h and it's .xib.
17.Open your MainWindow.xib, expand your Navigation Controller, (Change your View Mode into List so you can expand the Controller).
18.When you expand the Navigation Controller, you should be able to see the Navigation Bar and View Controller (Root View Controller).
19.Select the View Controller then press command+4.
20.On the Class, select the Drop-Down box and locate your View Controller, the one you created earlier. Save and Close your MainWindow.xib.
21.To test that your View Controller is now connected to your Navigation Controller, go to your View Controller .m. On it's viewDidLoad() make something like this:
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor brownColor];
}
22.Run the program, you should now see a brown screen