我想實現一個基本的UINavigationController
,我遇到了導航控制器顯示錯誤視圖的問題。UINavigationController顯示錯誤的視圖
我開始通過創建Xcode 4
這給了我下面的文件Window Based Application
:spellingAppDelegate.h
,spellingAppDelegate.m
和MainWindows.xib
。然後我添加了一個新的UIViewController
子類,並將其稱爲gameViewController
。
以下是我對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
下面的代碼是我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;
}
我的印象是,如果我運行上面的代碼,應用程序將啓動gameViewController.xib。但是,它顯示MainWindow.xib。我知道我可能錯過了一些基本的東西,但我無法弄清楚我做錯了什麼。謝謝。
謝謝。那工作。 – atbebtg