iphone - 多 View 应用程序在模拟器中显示空白屏幕

标签 iphone xcode multiview

我正在开发一个简单的应用程序,它首先显示一个菜单屏幕,当按下按钮时,会出现一个游戏屏幕。我能够毫无问题地开发游戏屏幕,但是当我更改代码以首先显示菜单时,模拟器显示空白屏幕。

我已经阅读了所有有关将 View 与 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

谢谢,

最佳答案

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

方法名称必须-applicationDidFinishLaunching:(不是-application:),否则UIKit可以'找不到它,将忽略初始化代码。

关于iphone - 多 View 应用程序在模拟器中显示空白屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2875135/

相关文章:

iphone - 如何在 Windows 上从提取的 ipa 包中提取 "uncrush"PNG? [png粉碎]

ios - UICollectionView 导航栏闪烁

android - Delphi Android 防止/处理多 View 模式

asp.net - 我可以在 aspx 页面上对每件事使用多 View 和 View 吗?

iphone - Cocos2d 与 UIKit View 混合 - 巨大的 FPS 下降

iphone - 如何正确使用ABPersonViewController 和ABPeoplePickerNavigationController 来查看联系人信息?

iPhone - 网站向左浮动

xcode - Xcode 中的预期标识符?我需要帮助!

ios - 为什么更改 UIImageView 内容模式会影响其在 Xcode6 中的自动布局?

iphone - Xcode 错误 : Incompatible Objective-C types. 预期为 'struct UIView'