0

Cocos2d を使用して iOS ゲームを作成しており、UITableView の外観をカスタマイズする必要があります。この投稿は、開始するのに適したフレームワークを提供しているようです 。サンプル コードは、単独でテストするとうまく機能します。問題は、cocos2d アプリで動作させることができないことです。

このサンプルでは、​​次のコードを使用してカスタム UIViewController を作成します (window は UIWindow で、viewController は EasyCustomTableController です)。

[window addSubview:viewController.view];
[window makeKeyAndVisible];

しかし、そのコードを使用すると、EasyCustomTableController の viewDidLoad 関数が実行されず、ゲーム内で何も起こりません。次のコードを使用して、viewDidLoad 関数を実行できます。

levelMenu = [[EasyCustomTableController alloc] init];
[[[CCDirector sharedDirector] openGLView] addSubview:levelMenu.view];

しかし、繰り返しますが、私のゲームでは何も起こらず、ビューは表示されません。

カスタム UIViewController を自分の cocos2d アプリで動作させるにはどうすればよいですか?

編集:

白い背景の UIView を表示できるので、levelMenu.view に問題があるはずです。

UIApplication* clientApp = [UIApplication sharedApplication];
UIWindow* topWindow = [clientApp keyWindow];
if (!topWindow) {
    topWindow = [[clientApp windows] objectAtIndex:0];
} 
//Works
UIView *white = [[UIView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
white.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:255];
[topWindow addSubview:white];

//Doesn't work
levelMenu = [[EasyCustomTableController alloc] init];
[topWindow addSubview:levelMenu.view];

levelMenu のクラス コードはサンプルから変更していません。ここの最初のコード ボックスで viewDidLoad を確認できます。

4

3 に答える 3

1

これを試して

UIApplication* clientApp = [UIApplication sharedApplication];   
UIWindow* topWindow = [clientApp keyWindow];
if (!topWindow) {
    topWindow = [[clientApp windows] objectAtIndex:0];
}
[topWindow addSubview:levelMenu.view];

何も表示されない場合は、levelMenu.view に問題がある可能性があります。これをテストするには、背景が白いシンプルな基本的な UIView を試してください。

于 2012-08-30T08:40:01.027 に答える
0

これを試して

[[[CCDirector sharedDirector] openGLView].superview addSubview:levelMenu.view];
于 2012-08-30T03:42:11.000 に答える
0

まず、CCLayer を作成し、cocos2d で作成したプッシュスクリーンを作成します。

[[CCDirector sharedDirector] pushScene:[ScoreLayer node]];

このレイヤーの ScoreLayer.h

    @interface ScoreLayer : CCLayer <UITableViewDelegate,UITableViewDataSource>{
        AppController *myApp;
        UIView *view;
        UITableView *tblView;
 UIToolbar *toolbar;
    UIBarButtonItem *backButton;
    NSMutableArray *ScoreArray;

    }
    @property(nonatomic,retain) UITableView *tblView;

ScoreLayer.m

-(id) init
{
    myApp = (AppController *)[UIApplication sharedApplication].delegate;
    self = [super init];
    // create view
    view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

    // create Table
    tblView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 436)];
    tblView.delegate = self;
    tblView.dataSource = self;
   // tblView.style = UITableViewStyleGrouped;
    //table.style = UITableViewStyleGrouped;

    ScoreArray = [myApp getScoreList];
    [view addSubview:tblView];
toolbar = [UIToolbar new];
    [toolbar setFrame:CGRectMake(0, 436, 320, 44)];
    toolbar.barStyle = UIBarStyleBlackOpaque;

    //Create a button
    backButton = [[UIBarButtonItem alloc] initWithTitle:@"Return to the main menu" style:UIBarButtonItemStyleBordered target:self action:@selector(backClicked:)];

    [toolbar setItems:[NSArray arrayWithObjects:backButton,nil] animated:YES];
    [view addSubview:toolbar];
    [toolbar release];

    // add the view to the director
    [[[CCDirector sharedDirector] openGLView] addSubview:view];

    return self;
}
于 2012-08-30T07:14:15.777 に答える