gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:23:14 25 4
gpt4 key购买 nike

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

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com