Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 更改视图时出现黑屏_Iphone_Ios_Xcode - Fatal编程技术网

Iphone 更改视图时出现黑屏

Iphone 更改视图时出现黑屏,iphone,ios,xcode,Iphone,Ios,Xcode,我在Xcode中创建了一个游戏,现在我决定给它添加一个菜单,菜单是第一个加载视图,所以我改变了 self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; 致: 现在,我的游戏所在的视图是:ViewController.m,从菜单中我可以看到: -(IBAction)gogame:(id)sender { UIViewController *

我在Xcode中创建了一个游戏,现在我决定给它添加一个菜单,菜单是第一个加载视图,所以我改变了

self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
致:

现在,我的游戏所在的视图是:ViewController.m,从菜单中我可以看到:

-(IBAction)gogame:(id)sender {
UIViewController *Game = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Game animated:YES];}
因为我需要给ViewController.m起一个名字,我在.h和.m中更改了这个名字:

@将ViewController接口到.h中的@interface GameViewController

和@implementation ViewController到.m中的@implementation GameViewController

现在,我让菜单“gogame”中的按钮运行它,当我点击按钮时,它会从菜单转到一个黑屏,它不会崩溃或发生任何事情,它只显示状态栏和一个黑屏。xCode给我的唯一问题是应用内委托:从“MenuViewController*”分配给“GameViewController*”的指针类型不兼容


我不知道为什么这不起作用,我希望有人能解释我,告诉我如何解决这个问题。感谢

UIViewController本身没有什么用处,它是用来添加行为的,因此在您的方法中:

以下是您对此方法的版本:

-(IBAction)gogame:(id)sender {
    UIViewController *Game = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:Game animated:YES];
}
它正按照您的要求进行操作,提供一个UIViewController提供的框架。您没有添加任何额外的行为或自定义视图

我很难完全解释您当前的代码设置,但听起来您的新类GameViewController就是您想要显示的,所以请将其更改为:

-(IBAction)gogame:(id)sender {
    GameViewController *Game = [[[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil] autorelease];
    [self presentModalViewController:Game animated:YES];
}
基于您对类名的重命名/重构,我不确定控制器的xib文件的名称。它是最初的“ViewController”还是您也将其更新为“GameViewController”(就像您应该做的那样)


关于警告,您在哪里创建和分配GameViewController?

UIViewController本身没有任何用处,它提供了添加行为的功能,因此在您的方法中:

以下是您对此方法的版本:

-(IBAction)gogame:(id)sender {
    UIViewController *Game = [[UIViewController alloc] initWithNibName:nil bundle:nil];
    [self presentModalViewController:Game animated:YES];
}
它正按照您的要求进行操作,提供一个UIViewController提供的框架。您没有添加任何额外的行为或自定义视图

我很难完全解释您当前的代码设置,但听起来您的新类GameViewController就是您想要显示的,所以请将其更改为:

-(IBAction)gogame:(id)sender {
    GameViewController *Game = [[[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil] autorelease];
    [self presentModalViewController:Game animated:YES];
}
基于您对类名的重命名/重构,我不确定控制器的xib文件的名称。它是最初的“ViewController”还是您也将其更新为“GameViewController”(就像您应该做的那样)


关于警告,您在哪里创建和分配GameViewController?

Owh我认为*Game我告诉它它是UIViewController'Game'Nope“Game”只是一个变量名,仅此而已。O文件名只是ViewController,还是让我更改它们以感谢您是的,最好的做法是使用“GameViewController”也与文件名匹配,一个la GameViewController.h和GameViewController.mI以前尝试过这个菜单,我遇到了一个问题,这就是为什么我在这里问这个问题,但现在我得到了相同的错误。Apple Mach-o链接(id)错误,链接器命令失败,退出代码为1(使用-v查看调用)Owh我想通过*Game我告诉它是UIViewController'Game'Nope“Game”仅仅是一个变量名,没有更多。O文件名只是ViewController还是让我更改这些来感谢你是的,最好的做法是使用“GameViewController”这样的类名“与文件名也匹配,la GameViewController.h和GameViewController.mI以前尝试过这个菜单,我遇到了一个问题,这就是为什么我在这里问这个问题,但现在我遇到了同样的错误。”。Apple Mach-o链接(id)错误,链接器命令失败,退出代码为1(使用-v查看调用)