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も含まれています。

ありがとう、B

4

2 に答える 2

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

メソッド名は(not ) でなければなりません。それ以外の場合、UIKit はそれを見つけることができず、初期化コードを無視します。-applicationDidFinishLaunching:-application:

于 2010-05-21T19:42:19.797 に答える
0

Pong_Multiple_ViewAppDelegate.mで、を使用してビューを追加しようとします

[window addSubview:[navigationController view]];

NavigationControllerがどこでもインスタンス化されていることを確認しますか?コードで、またはペン先を使用して?

于 2010-05-21T19:30:37.380 に答える