我正在开发一个首先显示菜单屏幕的简单应用程序,当按下按钮时,会出现一个游戏屏幕。我能够在没有任何问题的情况下开发游戏画面,但是当我将代码更改为首次显示菜单时,模拟器显示为空白屏幕。
我已经阅读了有关与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
谢谢, 乙
答案 0 :(得分:1)
- (void)application:(UIApplication *)application{
方法名称 必须 为-applicationDidFinishLaunching:
(不是-application:
),否则UIKit无法找到它并忽略初始化代码。
答案 1 :(得分:0)
在Pong_Multiple_ViewAppDelegate.m
中,您尝试使用
[window addSubview:[navigationController view]];
您确定navigationController在任何地方实例化吗?在代码中还是使用笔尖?