2010-05-20 125 views
2

我正在開發一個簡單的應用程序,首先顯示一個菜單屏幕,當按下按鈕時,會出現一個遊戲屏幕。我能夠在沒有任何問題的情況下開發遊戲屏幕,但是當我更改代碼以首先顯示菜單時,模擬器顯示空白屏幕。多視圖應用程序顯示模擬器中的空白屏幕

我已閱讀所有與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

謝謝, 乙

回答

0

在你Pong_Multiple_ViewAppDelegate.m,您嘗試添加使用視圖

[window addSubview:[navigationController view]]; 

你確定navigationController在任何地方被實例化嗎?無論是在代碼或使用筆尖?

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

方法名必須-applicationDidFinishLaunching:(不-application:),否則UIKit中無法找到它,而忽略初始化代碼。

相關問題