多视图应用程序显示模拟器中的空白屏幕

问题描述:

我正在开发一个简单的应用程序,首先显示一个菜单屏幕,当按下按钮时,会出现一个游戏屏幕。我能够在没有任何问题的情况下开发游戏屏幕,但是当我更改代码以首先显示菜单时,模拟器显示空白屏幕。多视图应用程序显示模拟器中的空白屏幕

我已阅读所有与IB连接意见的文章,但我无法弄清楚这一点。

任何帮助,将不胜感激。

这是我的代码:

// Pong_Multiple_ViewAppDelegate.h 
// Pong Multiple View 
// 
// Created by Brett on 10-05-19. 
// Copyright __MyCompanyName__ 2010. All rights reserved. 
// 

#import <UIKit/UIKit.h> 

@class MenuViewController; 

@interface Pong_Multiple_ViewAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
MenuViewController *navigationController; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet MenuViewController *navigationController; 

@end 


// 
// Pong_Multiple_ViewAppDelegate.m 
// Pong Multiple View 
// 
// Created by Brett on 10-05-19. 
// Copyright __MyCompanyName__ 2010. All rights reserved. 
// 

#import "Pong_Multiple_ViewAppDelegate.h" 
#import "MenuViewController.h" 

@implementation Pong_Multiple_ViewAppDelegate 

@synthesize window; 
@synthesize navigationController; 


- (void)application:(UIApplication *)application{  

    // Override point for customization after application launch 
[window addSubview:[navigationController view]]; 
    [window makeKeyAndVisible]; 

} 


- (void)dealloc { 
[navigationController release]; 
    [window release]; 
    [super dealloc]; 
} 


@end 

// 
// MenuViewController.h 
// Pong Multiple View 
// 
// Created by Brett on 10-05-19. 
// Copyright 2010 __MyCompanyName__. All rights reserved. 
// 

#import <UIKit/UIKit.h> 
#import "GameViewController.h" 


@interface MenuViewController : UIViewController { 

GameViewController *gameViewController; 
IBOutlet UIButton *gameButton; 

} 

@property(nonatomic, retain) GameViewController *gameViewController; 
@property(nonatomic, retain) UIButton *gameButton; 

-(IBAction)switchPage:(id)sender; 

@end 

// 
// MenuViewController.m 
// Pong Multiple View 
// 
// Created by Brett on 10-05-19. 
// Copyright 2010 __MyCompanyName__. All rights reserved. 
// 

#import "MenuViewController.h" 
#import "GameViewController.h" 


@implementation MenuViewController 

@synthesize gameViewController; 
@synthesize gameButton; 


-(IBAction)switchPage:(id)sender{ 
if (self.gameViewController==nil) { 
    GameViewController *gameView = [[GameViewController alloc]initWithNibName:@"GameView" bundle:[NSBundle mainBundle]]; 
    self.gameViewController= gameView; 
    [gameView release]; 

} 

[self.navigationController pushViewController:self.gameViewController animated:YES]; 

} 

.... 

@end 

我的代码还包括类:GameViewController.h,GameViewController.m和笔尖文件:MenuView.xib和GameView.xib

谢谢, 乙

在你Pong_Multiple_ViewAppDelegate.m,您尝试添加使用视图

[window addSubview:[navigationController view]]; 

你确定navigationController在任何地方被实例化吗?无论是在代码或使用笔尖?

- (void)application:(UIApplication *)application{  

方法名必须-applicationDidFinishLaunching:(不-application:),否则UIKit中无法找到它,而忽略初始化代码。