iphone - 切换 View 时黑屏

标签 iphone ios xcode

我在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/

相关文章:

iphone - 如何检测iphone中的某个按钮是否被点击

ios - 如何将按钮从一个位置移动到另一个位置?

ios - 如何在 Iphone 中共享图像和文本

iphone - opengl 1.1 在启动时搞砸了(随机)

iphone - 从 iPhone 到服务器的最大上传大小

ios - 我已经更改了我的应用程序的数据库,如果我将上传到苹果商店那么会发生什么?

ios - 在 Swift 中使用 RestKit

ios - 更改图标颜色选项卡栏 Controller -SWIFT

iOS 对等宽/等高按钮网格的约束导致定位和大小发生变化

ios - 检测以纵向或横向全屏播放的视频