我正在使用 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