I’m trying to implement a basic UINavigationController and I’m running into an issue with the navigation controller displaying a wrong view.
I started by creating a Window Based Application in Xcode 4 that gave me the following files:spellingAppDelegate.h, spellingAppDelegate.m and MainWindows.xib. I then added a new UIViewController subclass and call it gameViewController.
The following is my code for myAppDelegate.h
#import <UIKit/UIKit.h>
@interface spellingAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UINavigationController *navigationController;
@end
the following is my myAppDelegate.m
#import "spellingAppDelegate.h"
#import "gameViewController.h"
#import "resultViewController.h"
@implementation spellingAppDelegate
@synthesize window = window;
@synthesize navigationController = navigationController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window makeKeyAndVisible];
// create the MyView controller instance:
gameViewController *controller = [[gameViewController alloc] initWithNibName:@"gameViewController" bundle:nil];
// set the title that appears in the navigation bar:
[controller.navigationItem setTitle:@"Main View"];
// create the Navigation Controller instance:
UINavigationController *newnav = [[UINavigationController alloc] initWithRootViewController:controller];
// set the navController property:
[self setNavigationController:newnav];
// release both controllers:
[newnav release];
[controller release];
// add the Navigation Controller's view to the window:
[window addSubview:[navigationController view]];
return YES;
}
I was under the impression that if i run the above code, the app will start with gameViewController.xib. However, its displaying MainWindow.xib. I know I’m probably miss something basic but I can’t figure out what I did wrong. Thank you.
Try this it will work