views:

93

answers:

2

Hello;

I am developing a simple app that first shows a menu screen, and when a button is pressed, a game screen appears. I was able to develop the game screen without any issues, but when I changed the code to first display the menu, the simulator showed a blank screen.

I've read all the articles on connecting views with IB but I can't figure this out.

Any help would be appreciated.

This is my code:

//  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 

My code also includes classes: GameViewController.h, GameViewController.m, and nib files: MenuView.xib, and GameView.xib

Thanks, B

A: 

In your Pong_Multiple_ViewAppDelegate.m, you try to add a view using

[window addSubview:[navigationController view]];

Are you sure that navigationController is instantiated anywhere? Either in code or using a nib?

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

The method name must be -applicationDidFinishLaunching: (not -application:), otherwise UIKit can't find it and will ignore the initialization code.

KennyTM