簡體   English   中英

更改視圖時黑屏

[英]Black screen when changing view

我用Xcode創建了一個游戲,現在我決定向其中添加一個菜單,該菜單是第一個加載視圖,因此我進行了更改

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

至:

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

現在我的游戲所在的視圖是:ViewController.m,然后從菜單中轉到:

-(IBAction)gogame:(id)sender {
UIViewController *Game = [[UIViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Game animated:YES];}

因為我需要給ViewController.ma命名,所以在.h和.m中進行了更改:

.h中的@interface ViewController到@interface GameViewController

.m中的@implementation ViewController和@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?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM