2010-05-20 4 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

Спасибо, B

ответ

0

в вашем Pong_Multiple_ViewAppDelegate.m, вы пытаетесь добавить вид, используя

[window addSubview:[navigationController view]]; 

Вы уверены, что navigationController создан где-нибудь? Либо в коде или с помощью наконечника?

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

Имя метода должен быть -applicationDidFinishLaunching: (не -application:), в противном случае UIKit не может найти его, и будет игнорировать код инициализации.