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 和 nib 文件:MenuView.xib 和 GameView.xib

谢谢,乙

4

2 回答 2

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

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

于 2010-05-21T19:42:19.797 回答
0

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

[window addSubview:[navigationController view]];

您确定在任何地方都实例化了 navigationController 吗?是在代码中还是使用笔尖?

于 2010-05-21T19:30:37.380 回答