我在Xcode中创建了一个游戏,现在我决定给它添加一个菜单,菜单是第一个加载 View 所以我改变了
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
到:
self.viewController = [[[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil] autorelease];
现在我的游戏所在的 View 是:ViewController.m 并且从菜单我去那里:
-(IBAction)gogame:(id)sender {
UIViewController *Game = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Game animated:YES];}
因为我需要给 ViewController.m 命名,所以我在 .h 和 .m 中更改了名称:
.h 中的@interface ViewController 到@interface GameViewController
和@implementation ViewController 到.m 中的@implementation GameViewController
现在我让菜单“gogame”中的按钮运行它,当我单击该按钮时,它从菜单转到黑屏,它没有崩溃或任何东西它只显示状态栏和黑屏。 xCode 给我的唯一问题是在应用程序委托(delegate)中:从“MenuViewController *”分配给“GameViewController *”的不兼容指针类型。
我不知道为什么这不起作用我希望有人能解释我并告诉我如何解决这个问题。谢谢
最佳答案
单独的 UIViewController 没有任何用处,提供了添加行为的功能,因此在您的方法中:
这是此方法的版本:
-(IBAction)gogame:(id)sender {
UIViewController *Game = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Game animated:YES];
}
它完全按照您的指示进行操作,呈现一个提供 UIViewController 的框架。您还没有添加任何额外的行为或自定义 View 。
我无法完全解释您当前的代码设置,但听起来您的新类 GameViewController 是您想要显示的内容,因此请将其更改为:
-(IBAction)gogame:(id)sender {
GameViewController *Game = [[[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil] autorelease];
[self presentModalViewController:Game animated:YES];
}
根据您对类名的重命名/重构,我不确定 Controller 的 xib 文件的名称是什么。它是原始的“ViewController”还是您也将其更新为“GameViewController”(如您所愿)?
关于警告,您在哪里创建和分配 GameViewController?
关于iphone - 切换 View 时黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10956902/